]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Surface driver connection object when using a proxied dialect
authorFederico Caselli <cfederico87@gmail.com>
Tue, 31 Aug 2021 21:03:18 +0000 (23:03 +0200)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 17 Sep 2021 22:08:42 +0000 (18:08 -0400)
commit26140c08111da9833dd2eff0b5091494f253db46
tree61a64b7361ab0890521771a5d185db787482eaaf
parent204fe7ea206a1b0ab4ae248006f99afd15fa7f72
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
32 files changed:
README.dialects.rst
doc/build/changelog/unreleased_14/6832.rst [new file with mode: 0644]
doc/build/core/connections.rst
doc/build/core/internals.rst
doc/build/core/pooling.rst
doc/build/faq/connections.rst
lib/sqlalchemy/connectors/pyodbc.py
lib/sqlalchemy/dialects/mysql/aiomysql.py
lib/sqlalchemy/dialects/mysql/asyncmy.py
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/oracle/cx_oracle.py
lib/sqlalchemy/dialects/postgresql/asyncpg.py
lib/sqlalchemy/dialects/postgresql/pg8000.py
lib/sqlalchemy/dialects/postgresql/psycopg2.py
lib/sqlalchemy/dialects/sqlite/aiosqlite.py
lib/sqlalchemy/dialects/sqlite/pysqlite.py
lib/sqlalchemy/engine/__init__.py
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/engine/default.py
lib/sqlalchemy/engine/interfaces.py
lib/sqlalchemy/ext/asyncio/engine.py
lib/sqlalchemy/pool/base.py
lib/sqlalchemy/pool/events.py
lib/sqlalchemy/pool/impl.py
lib/sqlalchemy/testing/engines.py
lib/sqlalchemy/testing/plugin/pytestplugin.py
lib/sqlalchemy/util/langhelpers.py
test/dialect/postgresql/test_dialect.py
test/engine/test_execute.py
test/engine/test_pool.py
test/engine/test_reconnect.py
test/ext/asyncio/test_engine_py3k.py