Skip to content

Commit

Permalink
make some monkey-patching conditional on the version of SQLAlchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
moredip committed Nov 21, 2024
1 parent 7e1a976 commit ab6c5e4
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ def _instrument(self, **kwargs):
tracer, connections_usage, enable_commenter, commenter_options
),
)
_w(
"sqlalchemy.engine.create",
"create_engine",
_wrap_create_engine(
tracer, connections_usage, enable_commenter, commenter_options
),
)
# sqlalchemy.engine.create is not present in earlier versions of sqlalchemy (which we support)
if parse_version(sqlalchemy.__version__).release >= (1, 4):
_w(
"sqlalchemy.engine.create",
"create_engine",
_wrap_create_engine(
tracer, connections_usage, enable_commenter, commenter_options
),
)
_w(
"sqlalchemy.engine.base",
"Engine.connect",
Expand Down Expand Up @@ -231,7 +233,8 @@ def _instrument(self, **kwargs):
def _uninstrument(self, **kwargs):
unwrap(sqlalchemy, "create_engine")
unwrap(sqlalchemy.engine, "create_engine")
unwrap(sqlalchemy.engine.create, "create_engine")
if parse_version(sqlalchemy.__version__).release >= (1, 4):
unwrap(sqlalchemy.engine.create, "create_engine")
unwrap(Engine, "connect")
if parse_version(sqlalchemy.__version__).release >= (1, 4):
unwrap(sqlalchemy.ext.asyncio, "create_async_engine")
Expand Down

0 comments on commit ab6c5e4

Please sign in to comment.