Reputation: 464
I have a model called SignupTokens, we are updating entity with isUsed = True when user is confirm their from our chatbot, after updating entity if we query for not used token for specific same email with isUsed = False then some time result is back even there were isUsed flag already updated with True. We have double check in datastore entity is single at the time whenever we are facing this problem.
SignupTokens.gql("where isUsed = :1 and email = :2",False,email).get()
We have already try to use_cache = False like
SignupTokens.gql("where isUsed = :1 and email = :2",False,email).get(use_cache=False)
Pls let me know any one has idea about it.
Upvotes: 1
Views: 190
Reputation: 2344
As @Dan suggested this is most likely not an ndb
caching problem. It is the problem caused when you are reading and writing the same entity group continuously. This is a datastore behavior which is basically caused due to datastore contention and eventual consistency.
There are certain ways you can avoid this situation.
Query using key
. Whenever you try to read an object via its key it is strongly consistent
. So, In your case, I would suggest to store the key of the object you are updating, if possible and then read it and perform the operations you want.
Another approach would be to use NDB Asynchronous Operations. See related documentation here.
You can try to provide a delay which could help you but the delay should be provided in such a way that it is sufficient for the object to get updated.
Hope this answers your question!!!
Upvotes: 1
Reputation: 39824
This is most likely not an ndb caching problem, it's the expected datastore behaviour due to eventual consistency: it will take some time from the moment an entity's isUsed
property is set to True
until the index corresponding to your query is updated accordingly.
Until the index is updated the query results will not reflect the change.
Upvotes: 2