Matt Matt - 2 months ago 18
Python Question

Wait for datastore changes before redirecting

Very similar to this question, except that the answer is not suitable.

I populate a table from a datastore query, then there is a link allowing the user to delete a specific row. Clicking the link goes to a url that deletes the row from the datastore then redirects back to the table.

Changes more often than not aren't shown in the table until reloading again.

Easy solution is to redirect to another page, that uses a javascript redirect to add a delay of a couple of seconds. Other alternative is to send details back to the page like

action=delete&key=###
and then make sure that item is missed from the table. That's a pain though.

Answer

The answer is with ancestor queries. https://cloud.google.com/appengine/docs/python/datastore/queries#Python_Ancestor_queries

Create the entities with a parent. When one of the entities is deleted, you can run an ancestor query for your table list view which will have strong consistency when data is changed.

Example ancestor query:

tom = Person(key_name='Tom')

photo_query = Photo.all()
photo_query.ancestor(tom)