0

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'])
Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
phoebus
  • 21
  • 3

1 Answers1

1

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.

Community
  • 1
  • 1
Tim Hoffman
  • 12,976
  • 1
  • 17
  • 29
  • I don't think that the combination of PolyModel and StructuredProperty has to do anything with my problem. – phoebus Feb 01 '15 at 20:47
  • Actually it does. Read guido's comment about supporting StructuredProperties with PolyModel. NDB really doesn't support that combination. If you start looking at how metaclasses are used and also how PolyModel is implemented you will realize that what you are trying to do isn't currently going to work. I suggest you log a bug. – Tim Hoffman Feb 04 '15 at 10:31