Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async context manager for transactions #31

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hawkowl
Copy link
Contributor

@hawkowl hawkowl commented Oct 7, 2016

No description provided.

@codecov-io
Copy link

codecov-io commented Oct 7, 2016

Current coverage is 98.15% (diff: 100%)

No coverage report found for master at 699f2e8.

Powered by Codecov. Last update 699f2e8...8b73d16

@glyph
Copy link
Collaborator

glyph commented Oct 8, 2016

I love the idea for the feature, and the docs are great.

However, I don't love using an async context manager for this. For some simple cases, it might be good to have a context manager, but there are a number of reasons to avoid it:

  1. There's the obvious point that it only works in 3.5+. Still a lot of legacy code that won't be usable with this for years to come; transactions are not a "fancy" or optional feature. You need them for any even halfway-functioning SQL application.
  2. It's an abstraction inversion. There should be a nice transaction object which can be started and finished with just regular ol' methods before we get into a specific convenience layer (in large part because if this async with convenience layer is a good idea, it should still be implemented in a way where the underlying logic is usable in <3.5).
  3. It's a limiting design, because it highlights one of the weaknesses of context managers generally: the only-execute-once nature of their specification. In more sophisticated / concurrent database applications, transactions which create conflicts should be automatically retried. This means the transaction needs to be a callable, that can be called multiple times. Context managers have no API for re-entering, and it would be awkward in the extreme to require everyone who wants correct, retry-on-conflict transactions to do something like async with Transaction(...) as blub: while blub.transaction_should_keep_going: try: ... except RetriableTransactionException: pass

@glyph
Copy link
Collaborator

glyph commented Oct 8, 2016

For reference, the hacky implementation of this I've been prototyping with is here.

"country": "United States of America",
"comments": "In New York State"}])
raise Exception("Whoops!")
except:
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should really be raising/catching specific exception types; except: sets a really bad example


[testenv]
deps =
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = py.test
commands =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you put these config changes in a separate PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants