ctx = tasklets.get_context()
ctx.set_cache_policy(False)
ctx.set_memcache_policy(False)
(You also have to add from ndb import tasklets to the top.)
Let me know if that changes the outcome, and how. If it does, it is an
NDB issue; if it doesn't, it is not specific to NDB. If it isn't an
NDB issue, there are all sorts of subtle semantics associated with
transactions that I can't quite enumerate, and it could well be that
ancestor queries inside transactions always query the state at the
start of the transaction.
--Guido
--
--Guido van Rossum (python.org/~guido)
Stephen
Now I realise that I just restated what Amy already said at the bottom of her original post. Sorry about the noise - I'll read more carefully in future!
Stephen
The outcome: Interestingly, with caching off, the direct fetch by key
does *not* reflect the in-txn modifications either (in contrast to the
cache-enabled behaviour, where it did). So the inconsistency does
seem to be cache-related.
Yes- just documenting this makes sense to me too. I think the
distinction would be clear.
The instance cache during transactions is really useful (saves me from having to write it myself), but the behavior of the ancestor query is not what I would expect. I also expected that modified instances would be returned.
Tijmen
So what do I have to do if I want to get instances from the cache with a ancestor query during a transaction? I suppose doing a keys-only ancestor query and then fetching by key would return in the instances from the cache, but it feels a bit of a workaround.
The instance cache during transactions is really useful (saves me from having to write it myself), but the behavior of the ancestor query is not what I would expect. I also expected that modified instances would be returned.