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
Conversation
28fa0b9
to
f04c37d
Compare
@blueyed Does it work for you? |
django/test/testcases.py
Outdated
# 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🤔
f04c37d
to
4d3c61c
Compare
Thanks for the review @felixxm 🙏 I pushed some changes in the commit. |
There was a problem hiding this 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()
.
ticket-33277
Picked up from #17075