Reputation: 21
I have a polymodel for all contacts
from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel
class Contact(polymodel.PolyModel):
telephone = ndb.StructuredProperty(Telephone, repeated=True)
email = ndb.StructuredProperty(Email, repeated=True)
The Telephone and Email model classes have two simple StringProperty
properties: type
and value
.
I have a model Person
who uses this polymodel:
class Person(Contact):
name = ndb.StringProperty()
I would like to use projection to reduce the amount of output. So when I query a property of the parent (i.e. polymodel), such as:
qry = Person.query(projection=['telephone.value'])
everything works. But if I query a property of the Person
class, (either of)
qry = Person.query(projection=['name'])
qry = Person.query(projection=[Person.name])
I receive an InvalidPropertyError: Unknown property name
exception.
Is this a bug of ndb to look into the kind and not the actual class?
Please let me know if there is a way around it (of course one is to not use polymodels). Thanks.
EDIT:
Below I present a simpler model (removed StructuredProperty
) which gives the same issue:
class Contact(polymodel.PolyModel):
telephone = ndb.StringProperty()
class Person(Contact):
name = ndb.StringProperty()
This works:
qry = Person.query(projection=['telephone'])
This does not work:
qry = Person.query(projection=['name'])
Upvotes: 0
Views: 276
Reputation: 12986
There are a lot of problems trying to combine StructuredProperty with PolyModel - see ndb.StructuredProperty not calling ndb.PolyModel subclass methods and AppEngine NDB PolyModel getting properties for instance.
Basically the design of PolyModel and StructuredProperty tend to preclude their combined use.
I know you question is about projection queries but the fundamental problems here will no doubt get in the way of the projection query working.
Upvotes: 1