File tree 2 files changed +26
-3
lines changed
2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -305,9 +305,15 @@ def from_api_repr(cls, resource):
305
305
start_time = datetime_helpers .from_microseconds (1e3 * float (start_time ))
306
306
training_run ["startTime" ] = datetime_helpers .to_rfc3339 (start_time )
307
307
308
- this ._proto = json_format .ParseDict (
309
- resource , types .Model ()._pb , ignore_unknown_fields = True
310
- )
308
+ try :
309
+ this ._proto = json_format .ParseDict (
310
+ resource , types .Model ()._pb , ignore_unknown_fields = True
311
+ )
312
+ except json_format .ParseError :
313
+ resource ["modelType" ] = "MODEL_TYPE_UNSPECIFIED"
314
+ this ._proto = json_format .ParseDict (
315
+ resource , types .Model ()._pb , ignore_unknown_fields = True
316
+ )
311
317
return this
312
318
313
319
def _build_resource (self , filter_fields ):
Original file line number Diff line number Diff line change @@ -186,6 +186,23 @@ def test_from_api_repr_w_unknown_fields(target_class):
186
186
assert got ._properties is resource
187
187
188
188
189
+ def test_from_api_repr_w_unknown_type (target_class ):
190
+ from google .cloud .bigquery import ModelReference
191
+
192
+ resource = {
193
+ "modelReference" : {
194
+ "projectId" : "my-project" ,
195
+ "datasetId" : "my_dataset" ,
196
+ "modelId" : "my_model" ,
197
+ },
198
+ "modelType" : "BE_A_GOOD_ROLE_MODEL" ,
199
+ }
200
+ got = target_class .from_api_repr (resource )
201
+ assert got .reference == ModelReference .from_string ("my-project.my_dataset.my_model" )
202
+ assert got .model_type == 0
203
+ assert got ._properties is resource
204
+
205
+
189
206
@pytest .mark .parametrize (
190
207
"resource,filter_fields,expected" ,
191
208
[
You can’t perform that action at this time.
0 commit comments