Search code examples
pythongoogle-app-enginegoogle-cloud-datastoregql

How we can ignore NDB cached query result?


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.


Solution

  • 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.