From 26140c08111da9833dd2eff0b5091494f253db46 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 31 Aug 2021 23:03:18 +0200 Subject: Surface driver connection object when using a proxied dialect Improve the interface used by adapted drivers, like the asyncio ones, to access the actual connection object returned by the driver. The :class:`_engine._ConnectionRecord` and :class:`_engine._ConnectionFairy` now have two new attributes: * ``dbapi_connection`` always represents a DBAPI compatible object. For pep-249 drivers, this is the DBAPI connection as it always has been, previously accessed under the ``.connection`` attribute. For asyncio drivers that SQLAlchemy adapts into a pep-249 interface, the returned object will normally be a SQLAlchemy adaption object called :class:`_engine.AdaptedConnection`. * ``driver_connection`` always represents the actual connection object maintained by the third party pep-249 DBAPI or async driver in use. For standard pep-249 DBAPIs, this will always be the same object as that of the ``dbapi_connection``. For an asyncio driver, it will be the underlying asyncio-only connection object. The ``.connection`` attribute remains available and is now a legacy alias of ``.dbapi_connection``. Fixes: #6832 Change-Id: Ib72f97deefca96dce4e61e7c38ba430068d6a82e --- lib/sqlalchemy/engine/default.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/engine/default.py') diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index 8bd8a121b..eff28e340 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -646,7 +646,7 @@ class DefaultDialect(interfaces.Dialect): % (", ".join(name for name, obj in trans_objs)) ) - dbapi_connection = connection.connection.connection + dbapi_connection = connection.connection.dbapi_connection for name, characteristic, value in characteristic_values: characteristic.set_characteristic(self, dbapi_connection, value) connection.connection._connection_record.finalize_callback.append( @@ -779,6 +779,9 @@ class DefaultDialect(interfaces.Dialect): name = unicode(name) # noqa return name + def get_driver_connection(self, connection): + return connection + class _RendersLiteral(object): def literal_processor(self, dialect): -- cgit v1.2.1