Reputation: 2592
I am saving one of the fields in datastore using:
self.user.expiration_date = datetime.datetime.utcnow() + datetime.timedelta(days=31)
self.user.put()
I am using Webapp2. After saving the user expiration date, I redirect the user to a method, where the following code is written.
user = User.all().filter('email =', self.session.get('email'))
digest = self.session.get('passwd').encode('utf-8', 'ignore')
user = user.filter('passwd =', digest).get()
self.user = user
However, after this, when I check for the expiration_date, its Null or previous value.
What should I do here to get correct value?
Upvotes: 0
Views: 101
Reputation: 6893
You are seeing the effects of Eventual Consistency in a NoSQL Datastore. This section explains what is up. https://cloud.google.com/datastore/docs/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore/#h.w3kz4fze562t
Basically there is a slight delay between when an entity is written and when those writes will be seen by a query. If you refetch the entity by its key, you will avoid this problem.
If you can replace the User.all()
query with a User.get_by_id()
call and then compare user.email == session.get('email') and user.password == digest
then you can avoid it.
Upvotes: 1