Google datastore - does it do lazy loading?
1 answer
Yes, db.ReferenceProperty fields are lazy loaded. From the docs :
ReferenceProperty automatically refers to model instances and model instances as properties: the model instance can be directly bound to the ReferenceProperty and its key will be used. The ReferenceProperty value can be used as if it were a model instance, and the repository object would be fetched and the model instance created when it was first used this way. Pristine reference properties do not ask for unnecessary data.
So for example:
# Any reference properties not loaded yet
customer = Customer.get_by_id(1)
print customer.name
print customer.address
# Assuming customer.order is a ReferenceProperty, now is when it
# would be loaded from the datastore.
print customer.order.created_at
+6
a source to share