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

Fixed #33277 -- Disallowed database connections in threads in SimpleTestCase. #17639

Merged
merged 1 commit into from Jan 3, 2024

Conversation

David-Wobrock
Copy link
Member

ticket-33277

Picked up from #17075

@David-Wobrock David-Wobrock force-pushed the ticket-33277 branch 7 times, most recently from 28fa0b9 to f04c37d Compare December 23, 2023 22:30
@David-Wobrock David-Wobrock marked this pull request as ready for review December 23, 2023 22:52
@felixxm
Copy link
Member

felixxm commented Dec 28, 2023

@blueyed Does it work for you?

Comment on lines 294 to 298
# Copied from BaseDatabaseWrapper.ensure_connection as the original as
# been patched at the base class level.
if self.connection is None:
with self.wrap_database_errors:
self.connect()
Copy link
Member

Choose a reason for hiding this comment

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

What about 3rd-party database backends with the custom ensure_connection() implementation?

Copy link
Member

Choose a reason for hiding this comment

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

Also, the original ensure_connection() is @async_unsafe decorated.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, copying the source code is a bad idea here 😛
Let's call the actual BaseDatabaseWrapper.ensure_connection method.

Now, the monkey-patching approach means that, as long as we call BaseDatabaseWrapper.ensure_connection, the behaviour should work as expected.
Meaning that the Sentry implementation should keep working I believe.
But if another backend overrides ensure_connection without calling super().ensure_connection(...), then the behaviour remains the same as today: database connections still work in threads.

Would there be another method(s) that we can leverage? 🤔

@David-Wobrock
Copy link
Member Author

Thanks for the review @felixxm 🙏 I pushed some changes in the commit.

@felixxm felixxm changed the title Fixed #33277 -- Blocked database connections in threads for SimpleTestCase. Fixed #33277 -- Disallowed database connections in threads in SimpleTestCase. Jan 3, 2024
Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

@David-Wobrock Thanks 👍

I pushed small edits to a release note, and used enterClassContext().

@felixxm felixxm merged commit 8fb0be3 into django:main Jan 3, 2024
35 checks passed
@David-Wobrock David-Wobrock deleted the ticket-33277 branch January 3, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants