-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref: fix typing for sentry.db.postgres.base #96694
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
Conversation
_set_isolation_level was removed in django/django@64a899d released in django 1.9
@auto_reconnect_connection | ||
def _cursor(self, *args, **kwargs): | ||
return super()._cursor() |
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.
def cursor
just calls def _cursor
anyway so this should be a tiny simplification
@@ -21,7 +21,7 @@ def inner(self, *args, **kwargs): | |||
raise | |||
|
|||
self.db.close(reconnect=True) | |||
self.cursor = self.db._cursor() | |||
self.cursor = self.db.cursor() |
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.
Bug: Auto-Reconnect Cursor Wraps Incorrectly
The auto_reconnect_cursor
decorator, when applied to CursorWrapper
methods, now incorrectly re-initializes self.cursor
to another CursorWrapper
instance instead of the raw underlying cursor. This happens because self.db.cursor()
returns a CursorWrapper
, leading to improper nested wrapping and breaking the CursorWrapper
's delegation mechanism.
Locations (1)
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.
that's what already happens silly bot
self.cursor = self.db.cursor() | ||
|
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.
Potential bug: Auto-reconnect logic double-wraps cursors, causing `AttributeError` or recursion when `self.cursor` is reassigned after reconnection.
- Description: The
CursorWrapper
expectsself.cursor
to be the underlying psycopg2 cursor. However, during a database reconnection, theauto_reconnect_cursor
decorator atsrc/sentry/db/postgres/decorators.py:24
assignsself.db.cursor()
toself.cursor
. Sinceself.db.cursor()
now returns aCursorWrapper
, this results in aCursorWrapper
containing anotherCursorWrapper
. This double-wrapping can lead toAttributeError
exceptions, infinite recursion, or method resolution issues when accessing cursor-specific methods, effectively crashing the application during reconnection events. - Suggested fix: Modify the
auto_reconnect_cursor
decorator to ensureself.cursor
is assigned the raw psycopg2 cursor, not anotherCursorWrapper
, after reconnection. This might involve adjustingself.db.cursor()
's behavior or explicitly unwrapping the cursor before assignment to prevent nested wrappers.
severity: 0.9, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.
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.
you too, read the original code
❌ 5 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
_set_isolation_level was removed in django/django@64a899d released in django 1.9