I'm seeing this in my flask application and ipython when looking up entities by their Key or id
the MailboxxOrder model has 2 KeyProperties: user and recipient both defined as User model entites
class MailboxxOrder(ndb.Model):
""" Model for mailboxx orders. """
_use_cache = True
_use_global_cache = True
user = ndb.KeyProperty(kind='User', required=True)
recipient = ndb.KeyProperty(kind='User', required=True)
When querying for the entities by id, NDB returns None in many cases for both properties
When values are returned both properties have the same value, even though the entity actually has different keys for both properties
shown here using NDB python 2.7
Code example python 2.7
In [3]: entity = MailboxxOrder.get_by_id(6678619968503808)
In [4]: entity.user
Out[4]: Key('User', 5129160508833792)
In [5]: entity.recipient
Out[5]: Key('User', 5127556472766464)
Code example python 3.7
In [5]: for x in range(0, 20):
...: print('------')
...: with client.context():
...: order = MailboxxOrder.get_by_id(6678619968503808, use_cache=False, use_memcache=False)
...: print(f'user: {order.user}')
...: print(f'recipient: {order.recipient}')
...: print('-----')
...:
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: None
recipient: None
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: None
recipient: None
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: None
recipient: None
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: None
recipient: None
-----
------
user: Key('User', 5127556472766464)
recipient: Key('User', 5127556472766464)
-----
------
user: None
recipient: None
-----
I'm seeing this in my flask application and ipython when looking up entities by their Key or id
the
MailboxxOrdermodel has 2KeyProperties:userandrecipientboth defined asUsermodel entitesWhen querying for the entities by id, NDB returns
Nonein many cases for both propertiesWhen values are returned both properties have the same value, even though the entity actually has different keys for both properties
shown here using NDB python 2.7
Code example python 2.7
Code example python 3.7