fix(dbapi2): preserve XRayTracedConn wrapper in connection context manager - #491
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #490
Problem
When using a database connection wrapped by \XRayTracedConn\ within a context manager (\with conn as c:), \wrapt.ObjectProxy\ forwards _enter_\ to the underlying database connection. Since DBAPI and driver \Connection.enter()\ returns \self\ (the underlying connection object), \c\ ends up referencing the unwrapped connection rather than \XRayTracedConn. Consequently, subsequent \c.cursor()\ calls return raw cursors, and SQL queries executed inside the context manager are not traced by X-Ray.
Root Cause
\XRayTracedCursor\ already implements _enter_\ to return \self\ when _wrapped_.enter()\ returns the underlying object, but \XRayTracedConn\ was missing the corresponding _enter_\ implementation.
Solution
Implement _enter_\ on \XRayTracedConn\ matching the existing pattern in \XRayTracedCursor:
\\python
def enter(self):
value = self.wrapped.enter()
if value is not self.wrapped:
return value
return self
\\
Validation