Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child property with Polymodel doesn't work #179

Closed
stepanovsh opened this issue Aug 29, 2019 · 1 comment · Fixed by #186
Closed

Child property with Polymodel doesn't work #179

stepanovsh opened this issue Aug 29, 2019 · 1 comment · Fixed by #186
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@stepanovsh
Copy link

Hi. We're trying to create new models on AppEngine Standard with PY3 runtime and have some problems with child Models if we use Polymodel

Models example

from google.cloud import ndb
from google.cloud.ndb import polymodel


class Foo(ndb.Model):
    timestamp = ndb.DateTimeProperty()


class TestPolymodel(polymodel.PolyModel):
    test_string = ndb.StringProperty(required=True)
    test_boolean = ndb.BooleanProperty()
    test_auto_now = ndb.DateTimeProperty(auto_now=True)
    test_auto_add = ndb.DateTimeProperty(auto_now_add=True)


class TestModel(TestPolymodel):
    test_key = ndb.KeyProperty(kind='Foo')
    test_strchild = ndb.StringProperty(required=True)
    test_boolchild = ndb.BooleanProperty()

When we try to save these models to datastore all information saved properly but when we try to retrieve them we received None values for child model keys

Code example

from google.cloud import ndb

ndb_client = ndb.Client()

with ndb_client.context(): 
    test_model = TestModel.get_by_id(5632763172487168)
    print(test_model.to_dict())

Print result

{'class_': ['TestPolymodel', 'TestModel'],
 'test_auto_add': datetime.datetime(2019, 8, 29, 8, 42, 25, 246185),
 'test_auto_now': datetime.datetime(2019, 8, 29, 8, 42, 25, 246191),
 'test_boolchild': None,
 'test_boolean': True,
 'test_key': None,
 'test_strchild': None,
 'test_string': 'test_string'}

But if we move some property to TestPolymodel class we can retrieve them

Models example

class TestPolymodel(polymodel.PolyModel):
    test_string = ndb.StringProperty(required=True)
    test_boolean = ndb.BooleanProperty()
    test_auto_now = ndb.DateTimeProperty(auto_now=True)
    test_auto_add = ndb.DateTimeProperty(auto_now_add=True)
    test_strchild = ndb.StringProperty(required=True)


class TestModel(TestPolymodel):
    test_key = ndb.KeyProperty(kind='Foo')
    test_boolchild = ndb.BooleanProperty()

with ndb_client.context(): 
    test_model = TestModel.get_by_id(5632763172487168)
    print(test_model.to_dict())

Print result

{'class_': ['TestPolymodel', 'TestModel'],
 'test_auto_add': datetime.datetime(2019, 8, 29, 8, 42, 25, 246185),
 'test_auto_now': datetime.datetime(2019, 8, 29, 8, 42, 25, 246191),
 'test_boolchild': None,
 'test_boolean': True,
 'test_key': None,
 'test_strchild': 'test_strchild',
 'test_string': 'test_string'}

As you can see we received the correct value for test_strchild

Thanks!

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. labels Aug 30, 2019
@cguardia cguardia added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. 🚨 triage me I really want to be triaged. labels Sep 3, 2019
@cguardia
Copy link
Contributor

cguardia commented Sep 3, 2019

Thanks a lot for you report. We'll take a look.

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed triage me I really want to be triaged. 🚨 This issue needs some love. 🚨 labels Sep 3, 2019
@chrisrossi chrisrossi self-assigned this Sep 6, 2019
chrisrossi pushed a commit to chrisrossi/python-ndb that referenced this issue Sep 9, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants