Skip to content Skip to sidebar Skip to footer

Gae Python Ndb .put Not Synchronous On Development (but Works In Production)?

The following below should create a Counter model and use (deferred) tasks to increment the counter to 10. Visiting '/' ought to create a single Counter object with count = 10. T

Solution 1:

The production 'synchronicity' is just apparent, it's not guaranteed (in your approach). It can always happen that a newly created counter is not found in the query, thus your code could create multiple counters.

More details in this Balancing Strong and Eventual Consistency with Google Cloud Datastore article.

Solution 2:

You should retrieve your counter by key and then you will avoid eventual consistency. Especially as you seem to only create a single Counter object. Not this won't scale if you have a large number of concurrent writes.

It would also pay to read the article linked to in the other answer. There a re number of problems with your approach.

Its seems odd to me that you would even consider using queries for this functionality. By specifying the key you will also guarantee a single counter entity.

Post a Comment for "Gae Python Ndb .put Not Synchronous On Development (but Works In Production)?"