File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
packages/google-cloud-ndb Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -527,7 +527,13 @@ def _entity_from_ds_entity(ds_entity, model_class=None):
527527 Returns:
528528 .Model: The deserialized entity.
529529 """
530- model_class = model_class or Model ._lookup_model (ds_entity .kind )
530+ class_key = ds_entity .get ("class" )
531+ if class_key :
532+ kind = class_key [- 1 ]
533+ else :
534+ kind = ds_entity .kind
535+
536+ model_class = model_class or Model ._lookup_model (kind )
531537 entity = model_class ()
532538
533539 # Check if we are dealing with a PolyModel, and if so get correct subclass.
Original file line number Diff line number Diff line change @@ -853,21 +853,24 @@ class SomeKind(ndb.Expando):
853853@pytest .mark .usefixtures ("client_context" )
854854def test_insert_polymodel (dispose_of ):
855855 class Animal (ndb .PolyModel ):
856- pass
856+ one = ndb . StringProperty ()
857857
858858 class Feline (Animal ):
859- pass
859+ two = ndb . StringProperty ()
860860
861861 class Cat (Feline ):
862- pass
862+ three = ndb . StringProperty ()
863863
864- entity = Cat ()
864+ entity = Cat (one = "hello" , two = "dad" , three = "i'm in jail" )
865865 key = entity .put ()
866866
867867 retrieved = key .get ()
868868
869869 assert isinstance (retrieved , Animal )
870870 assert isinstance (retrieved , Cat )
871+ assert retrieved .one == "hello"
872+ assert retrieved .two == "dad"
873+ assert retrieved .three == "i'm in jail"
871874
872875 dispose_of (key ._key )
873876
You can’t perform that action at this time.
0 commit comments