Skip to content
This repository was archived by the owner on May 6, 2026. It is now read-only.

fix: @non_transactional decorator was not working correctly with async#554

Merged
andrewsg merged 2 commits into
googleapis:masterfrom
chrisrossi:fix-552
Oct 2, 2020
Merged

fix: @non_transactional decorator was not working correctly with async#554
andrewsg merged 2 commits into
googleapis:masterfrom
chrisrossi:fix-552

Conversation

@chrisrossi
Copy link
Copy Markdown
Contributor

Fixes #552

@chrisrossi chrisrossi requested a review from cguardia October 1, 2020 20:39
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 1, 2020
"""
transaction = _get_transaction(options)

transaction = options.transaction
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what was going on was the transaction would be set or not for the batch when _datastore_api.lookup was called, but the call to _get_transaction would potentially fish the transaction out of the current context when the batch was actually run. The problem is that the call to lookup would be made in the context of a non_transactional and would correctly set the transaction to None, but then because the call to actually process the batch was delayed, it could happen outside of the non_transactional context, even though it is processing lookup calls made in the non_transactional context. The solution here is to just use the transaction set for the batch without referring to the current context. I'm pretty sure the call to _get_transaction is a fossil from a time before the transactions feature had been completely figured out. I have verified that in all cases the current transaction is set in options when the lookup call is made, so there really is no need to refer to the context.

Copy link
Copy Markdown
Contributor

@cguardia cguardia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. The explanation clears it up for me.

In all cases, we know where to get the transaction from.
Copy link
Copy Markdown
Contributor

@andrewsg andrewsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, especially for the regression tests!

@andrewsg andrewsg merged commit 758c8e6 into googleapis:master Oct 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NDB: non_transactional tasklets do not respect the non_transactional context

3 participants