@@ -340,10 +340,15 @@ def _construct_model_reference(cls, dct: Dict[str, object], type_: Type[T], obje
340
340
if reference_type is not model .ModelReference :
341
341
raise ValueError (f"Expected a reference of type { model .ModelReference } , got { reference_type } !" )
342
342
keys = [cls ._construct_key (key_data ) for key_data in _get_ts (dct , "keys" , list )]
343
- if keys and not issubclass (KEY_TYPES_CLASSES_INVERSE .get (keys [- 1 ].type , type (None )), type_ ):
343
+ last_key_type = KEY_TYPES_CLASSES_INVERSE .get (keys [- 1 ].type , type (None ))
344
+ if keys and not issubclass (last_key_type , type_ ):
344
345
logger .warning ("type %s of last key of reference to %s does not match reference type %s" ,
345
346
keys [- 1 ].type .name , " / " .join (str (k ) for k in keys ), type_ .__name__ )
346
- return object_class (tuple (keys ), type_ , cls ._construct_reference (_get_ts (dct , 'referredSemanticId' , dict ))
347
+ # Infer type the model refence points to using `last_key_type` instead of `type_`.
348
+ # `type_` is often a `model.Referable`, which is more abstract than e.g. a `model.ConceptDescription`,
349
+ # leading to information loss while deserializing.
350
+ return object_class (tuple (keys ), last_key_type ,
351
+ cls ._construct_reference (_get_ts (dct , 'referredSemanticId' , dict ))
347
352
if 'referredSemanticId' in dct else None )
348
353
349
354
@classmethod
0 commit comments