-
Notifications
You must be signed in to change notification settings - Fork 261
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
Connections and transactions meta issue #456
Comments
I spent some more time debugging the current code and I believe I found the issue with the transactions introduced in #328. As explained earlier it only happens when there's been a previous query to the database, which calls When
Finally, on The first instinct is to replace the context in the Database instance with the new one, however, that would mean the previous connection would be unreachable since there's only one context at any point in time. I believe this was a deliberate design choice, i.e. there should be a single Personally, I think the best course of action is to revert #328 since it caused a regression and tackle #327 starting from the API design, defining the semantics of what the user expects when opening transactions in concurrent tasks. |
@yeraydiazdiaz could one use a stack to keep track of connections? |
@yeraydiazdiaz |
Is there any status update on this? |
@emerson-h Looks like it was fixed in 0.6.0 🎉 |
The problem still exists |
@matthiasBT can you please clarify the behavior that still exists? Perhaps by including a code snippet? I imagine this issue is affected by the changes to transaction and connection context in #546 which has much discussion. If this issue is still affecting you on the latest version, the next step is to provide a failing test case that illustrates the problem. |
Hi all, we've been experiencing some issues with Databases regarding connection and transaction management, so I've spent some time reading through the different issues and PRs and understanding the code. There are couple cross cutting problems that I think need discussion as to how to best tackle them. I'll do my best to outline the past and pressent issues and their causes.
connection
method is called which checks for the presence of a connection in the context, if there is one it is returned, otherwise it creates a new connection and sets it in the context (https://github.com/encode/databases/blob/master/databases/core.py#L190-L202).transaction
is called a new connection is created. This change was part of the 0.5.0 release. However, this change led to issues where transactions are not rolled back correctly (Database transaction is not rollbacked #403, Clarification on transaction isolation and management #424, Transaction rollback seems to be unsuccessful #425), although it's not entirely clear to me why (any clarification on this respect would be appreciated).In summary, there's two valid use cases, concurrent transaction management and predictable non-concurrent transaction rollback, that seem at odds with each other in the current implementation. Ideally we'd find a solution for #327 that does not require creating a new connection per transaction.
I also think it might be worth clarifying the connection management model, the docs suggest the connections are handled transparently but it's unclear when actual backend connections are created, from the code it seems they're only created once on
Connection.__aenter__
and since the first created connection is set in the context and returned at all times, there's effectively a single backend connection acquired at any point in time.Hopefully this summary sparks a conversation around possible fixes for these problems, please do let me know if I misunderstood anything.
The text was updated successfully, but these errors were encountered: