@@ -696,26 +696,29 @@ def _entity_from_protobuf(protobuf):
696696 return _entity_from_ds_entity (ds_entity )
697697
698698
699- def _properties_of (entity ):
700- """Get the model properties for an entity .
699+ def _properties_of (* entities ):
700+ """Get the model properties for one or more entities .
701701
702- After collecting any properties local to the given entity , will traverse the
703- entity's MRO (class hierarchy) up from the entity's class through all of its
704- ancestors, collecting an ``Property`` instances defined for those classes.
702+ After collecting any properties local to the given entities , will traverse the
703+ entities' MRO (class hierarchy) up from the entities' class through all of its
704+ ancestors, collecting any ``Property`` instances defined for those classes.
705705
706706 Args:
707- entity (model.Model): The entity to get properties for.
707+ entities (Tuple[model.Model]): The entities to get properties for. All entities
708+ are expected to be of the same class.
708709
709710 Returns:
710- Iterator[Property]: Iterator over the entity's properties.
711+ Iterator[Property]: Iterator over the entities' properties.
711712 """
712713 seen = set ()
713714
714- for level in (entity ,) + tuple (type (entity ).mro ()):
715+ entity_type = type (entities [0 ]) # assume all entities are same type
716+ for level in entities + tuple (entity_type .mro ()):
715717 if not hasattr (level , "_properties" ):
716718 continue
717719
718- for prop in level ._properties .values ():
720+ level_properties = getattr (level , "_properties" , {})
721+ for prop in level_properties .values ():
719722 if (
720723 not isinstance (prop , Property )
721724 or isinstance (prop , ModelKey )
@@ -4299,6 +4302,8 @@ def _to_datastore(self, entity, data, prefix="", repeated=False):
42994302 if not self ._repeated :
43004303 values = (values ,)
43014304
4305+ props = tuple (_properties_of (* values ))
4306+
43024307 for value in values :
43034308 if value is None :
43044309 keys .extend (
@@ -4308,7 +4313,7 @@ def _to_datastore(self, entity, data, prefix="", repeated=False):
43084313 )
43094314 continue
43104315
4311- for prop in _properties_of ( value ) :
4316+ for prop in props :
43124317 keys .extend (
43134318 prop ._to_datastore (
43144319 value , data , prefix = next_prefix , repeated = next_repeated
0 commit comments