A query with projection returns doubles
Closed this issue · 4 comments
A query with projection returns a list of entities that contains doubles, same entities repeated many times.
Simple example:
result_1 = MyKind.query(ancestor=ancestor_key).fetch()
returns 6 entities, while
result_2 = MyKind.query(ancestor=ancestor_key).fetch(projection=["attr1", "attr2"])
returns 8 entities.
Doing [entity.key.id() for entity in result_2]
, we find that the query with projection has returned doubles, entities that are repeated in the result set.
This does not seem to be a documented behaviour.
This is documented behaviour at https://cloud.google.com/appengine/docs/legacy/standard/python/ndb/projectionqueries#Projections_and_multiple_valued_properties .
Specifically "Projecting a property with multiple values will not populate all values for that property. Instead, a separate entity will be returned for each unique combination of projected values matching the query"
Thanks a lot for the investigation and for the answer. So it is documented indeed. It looks like a weird design choice to me, but at least we know now.