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

set_roll_back should only rollback initialized connections #9599

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jdetaeye
Copy link

@jdetaeye jdetaeye commented Dec 9, 2024

The exception handler call "connections.all()". This creates a database connection to all defined databases. As a small optimization you can use "connections.all(initialized_only=True)" to rollback only the database to which the current thread has open connections.

(My application can have many databases defined, and this loop is identified as a source of many idle database connections)

Note: Before submitting a code change, please review our contributing guidelines.

Description

Please describe your pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. When linking to an issue, please use refs #... in the description of the pull request.

The exception handler call "connections.all()". This creates a database connection to all defined databases. 
As a small optimization you can use "connections.all(initialized_only=True)" to rollback only the database to which the current thread has open connections.

(My application can have many databases defined, and this loop is identified as a source of many idle database connections)
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

is it possible to add tests to avoid regression?

@jdetaeye
Copy link
Author

@auvipy I just looked into updating

def test_class_based_view_exception_handler(self):
with such a test. I failed creating a test case demonstrating the fix (maybe related to the in memory sqlite database used by the test?). Sorry, I won't be able to provide a test.

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.

2 participants