Open troberti opened 7 months ago
The problem is in google/appengine/ext/ndb/context.py:976
where the kwargs **ctx_options
is passed to the _make_ctx_options
function . This function parses the options but does not accept the read_only
keyword argument. This argument is used separately a few lines later to set the correct TransactionMode, but never gets there.
@tasklets.tasklet
def transaction(self, callback, **ctx_options):
options = _make_ctx_options(ctx_options, TransactionOptions)
propagation = TransactionOptions.propagation(options)
if propagation is None:
propagation = TransactionOptions.NESTED
mode = datastore_rpc.TransactionMode.READ_WRITE
if ctx_options.get('read_only', False):
mode = datastore_rpc.TransactionMode.READ_ONLY
Swapping the order around and removing the read_only
key from ctx_options
fixes the issue:
@tasklets.tasklet
def transaction(self, callback, **ctx_options):
mode = datastore_rpc.TransactionMode.READ_WRITE
if ctx_options.get('read_only', False):
mode = datastore_rpc.TransactionMode.READ_ONLY
ctx_options.pop('read_only')
options = _make_ctx_options(ctx_options, TransactionOptions)
propagation = TransactionOptions.propagation(options)
if propagation is None:
propagation = TransactionOptions.NESTED
Expected Behavior
The NDB transaction() function has a
read_only
property to indicate that the transaction will only perform entity reads, potentially improving throughput. I expect that it will start a read only transaction when I invoke it as such:ndb.transaction(txn, read_only=True)
.Actual Behavior
Sadly, this flag does not work in the current SDK. Instead, it fails with an
TypeError: Unknown configuration option ('read_only')
error when you specify it (regardless whether it is True of False).Full stack trace:
Steps to Reproduce the Problem
Run the following test:
Specifications
Version: appengine-python-standard 1.1.6