-
Notifications
You must be signed in to change notification settings - Fork 822
fix: Update PsycopgInstrumentor.instrument_connection to use async cursor factory
#3956
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
base: main
Are you sure you want to change the base?
fix: Update PsycopgInstrumentor.instrument_connection to use async cursor factory
#3956
Conversation
93f0638 to
b3a3ee1
Compare
|
Can we add some unit tests to cover this scenario? Also make sure to add a changelog entry. |
Yup, updated the existing tests and added a new test for this change. |
ddb7153 to
e2ff5af
Compare
xrmx
left a comment
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.
Please rebase / merge main and add a CHANGELOG entry.
e2ff5af to
5670b96
Compare
Rebased and updated the |
|
@dspatoulas pylint is not happy
|
@xrmx sorry about that, I ran the tests locally but not the linter 🤦♂️ |
Description
Update
PsycopgInstrumentor.instrument_connectionto support both sync and asyncpsycopgconnections by configuring the appropriatecursor_factory.Previously,
instrument_connectionalways used the sync cursor factory and did not properly handleAsyncConnectioninstances. As a result, calls made through an async connection would fail because of the async context.With this change:
connectionis apsycopg.AsyncConnection, we setconnection.cursor_factoryto_new_cursor_async_factory(...).connection.cursor_factoryto_new_cursor_factory(...).This aligns
instrument_connectionwith the behavior of the globalinstrument()helper and ensures both sync and async connections are correctly traced.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Updated the tests in the
psycopginstrumentation test suite to cover both sync and async connections, added a new test for the async connection code path that was previously not tested.Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.