Reputation: 1201
I was reading this StackOverflow question about eager loading which led me to this blog post about efficient dereferencing on GAE.
Is it correct, that if I dereference two ReferenceProperties that point to the same object in the datastore, the framework doesn't maintain any kind of identity map and performs two separate get requests? The objects returned are also different instances and changes on one are obviously not reflected on the other.
Isn't this less than ideal? I'm coming from a SQLAlchemy background, where I find the session pattern really intuitive.
Upvotes: 1
Views: 147
Reputation: 101149
That's correct. Guido's new NDB project does perform this mapping, but the current db framework doesn't. The reason for this is what you'd expect: if two different parts of the code fetch and modify the same entity, it could create unwanted side-effects. The intuitive expectation is that if you fetched the object, it's yours and nothing else is going to change it underneath you unless you want it to.
If you're trying to dereference a batch of entities at the same time, you can convert the list of keys into a set first to eliminate duplicate fetches.
Upvotes: 1