Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:23:26+00:00 2026-05-31T18:23:26+00:00

The apply phase of save may fail and/or is still being done asynchronously before

  • 0

The apply phase of save may fail and/or is still being done asynchronously before next not strongly-consistent read — non ancestor query.

Based on local testing article I have wrote a test that should simulate inconsistent reads:

import dev_appserver

dev_appserver.fix_sys_path()

import unittest
from google.appengine.ext import ndb
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_util

class SomeModel(ndb.Model):
    pass

class SingleEntityConsistency(unittest.TestCase):
    def setUp(self):
        # Setup AppEngine env
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
        self.testbed.init_memcache_stub()
        # A test key
        self.key = ndb.Key('SomeModel', 'test')

    def tearDown(self):
        self.testbed.deactivate()

    def test_tx_get_or_insert(self):
        p = SomeModel.get_or_insert('test')
        self.assertEqual(0, SomeModel.query().count(1), "Shouldn't be applied yet")
        self.assertEqual(1, SomeModel.query(ancestor=self.key).count(1), "Ancestor query read should be consistent")

    def test_no_tx_insert(self):
        p = SomeModel(id='test')
        p.put()
        self.assertEqual(0, SomeModel.query().count(2), "Shouldn't be applied yet")
        self.assertEqual(1, SomeModel.query(ancestor=self.key).count(1), "Ancestor query read should be consistent")

    def test_with_ancestor(self):
        p = SomeModel(id='test')
        p.put()
        self.assertEqual(p, SomeModel.query(ancestor=self.key).get())

    def test_key(self):
        p = SomeModel(id='test')
        p.put()
        self.assertEqual(p, self.key.get())

if __name__ == '__main__':
    unittest.main()

Actual questions…

  1. Does wrapping put() in transaction change behaviour described in the beginning? Do I still need a strongly consistent query to make a sure that I’ll read was was written in the txn? (tests suggest that, I still need strongly consistent query)

  2. Is key.get() considered to be strongly-consistent? (tests suggest that, it is)

UPDATE

I have updated test code as Guido mentioned, now all test pass:

self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:23:28+00:00Added an answer on May 31, 2026 at 6:23 pm

    I believe you must do something to activate the policy. That would explain the test failures. Also I believe only queries are affected and a lone put is effectively a transaction. Finally beware of NDB’s caches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to apply style only to the myPage id. But I am not
I'm in the design phase of a medium-sized PHP web application (not a static
I'm trying to apply border-radius effect on a particular div. The code I used
Need to apply a filter to a file like this: TUPAC_0006:1:1:2554:2356#0/1 0 * 0
Is it possible to apply a workflow in Sitecore only for a particular user?
I want to apply texture to the transparent png(bitmap), but I don't want to
I need to apply tint effect on image in Android . But the tint
i'm trying to apply the MVVM pattern in my application with MVVM Light. I've
Is it possible to apply a heading style (especially heading 3 as in excel
I want to apply scaling animation to UIButton.When user drag button upside of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.