Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on running transaction with multiple entity groups through nosetests

I am building an application with Python 2.7 using the Google App Engine framework. To test my application I have a several tests that are run through nosetests making use of the nosegae plugin. I run them with the following command:

nosetests --with-gae --gae-lib-root=/usr/local/google_appengine/ -w . -w */test/ -v

In the model layer of my application, I have the need to run several database operations that affect multiple entity groups inside the same transaction. I do this by making use of the run_in_transaction_options function of the db package: https://developers.google.com/appengine/docs/python/datastore/functions#run_in_transaction

Unfortunately, when running my test suites, I get the following error in those testcases that try to run such transaction:

BadRequestError: transactions on multiple entity groups only allowed with the High Replication datastore

I cannot find any flag in nosetests that makes it possible to enable the HRD.

I am wondering if it is possible at all to run HRD from nosetests and if so, how it can be set up?

like image 653
Jordi Chacón Avatar asked Oct 02 '12 17:10

Jordi Chacón


1 Answers

I would highly suggest you to switch from db to ndb, where you can use cross group transactions.

To simulate the HRD, you can add this part to the setUp function of your tests, from Writing High Replication Datastore tests:

# Create a consistency policy that will simulate the High Replication consistency model.
self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=0)

# Initialize the datastore stub with this policy.
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
like image 57
aschmid00 Avatar answered Sep 30 '22 16:09

aschmid00