From: Mike Bayer Date: Sun, 22 May 2022 18:28:14 +0000 (-0400) Subject: deprecate .connection on _ConnectionFairy, _ConnectionRecord X-Git-Tag: rel_2_0_0b1~293^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=656fd0d73a679a2588289e285328af707e9401d1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git deprecate .connection on _ConnectionFairy, _ConnectionRecord These are replaced by the read-only ManagesConnection.dbapi_connection attribute. For some reason both of these objects had "setter" for .connection as well; there's no use case for that at all so just remove setter logic entirely. Fixes: #6981 Change-Id: I6425de4a017f6370e1a7476cd491cabc55e55e67 --- diff --git a/lib/sqlalchemy/pool/base.py b/lib/sqlalchemy/pool/base.py index 22be96fad1..51eb5e9f5e 100644 --- a/lib/sqlalchemy/pool/base.py +++ b/lib/sqlalchemy/pool/base.py @@ -621,14 +621,14 @@ class _ConnectionRecord(ConnectionPoolEntry): self.dbapi_connection ) - @property + @util.deprecated_property( + "2.0", + "The _ConnectionRecord.connection attribute is deprecated; " + "please use 'driver_connection'", + ) def connection(self) -> Optional[DBAPIConnection]: return self.dbapi_connection - @connection.setter - def connection(self, value: DBAPIConnection) -> None: - self.dbapi_connection = value - _soft_invalidate_time: float = 0 @util.ro_memoized_property @@ -1156,14 +1156,14 @@ class _ConnectionFairy(PoolProxiedConnection): return None return self._connection_record.driver_connection - @property + @util.deprecated_property( + "2.0", + "The _ConnectionFairy.connection attribute is deprecated; " + "please use 'driver_connection'", + ) def connection(self) -> DBAPIConnection: return self.dbapi_connection - @connection.setter - def connection(self, value: DBAPIConnection) -> None: - self.dbapi_connection = value - @classmethod def _checkout( cls, diff --git a/test/dialect/oracle/test_dialect.py b/test/dialect/oracle/test_dialect.py index ad361b8794..26a29b73e6 100644 --- a/test/dialect/oracle/test_dialect.py +++ b/test/dialect/oracle/test_dialect.py @@ -135,7 +135,7 @@ class DialectWBackendTest(fixtures.TestBase): # cx_Oracle dialect does not raise this. eq_(conn.dialect.default_isolation_level, None) - dbapi_conn = conn.connection.connection + dbapi_conn = conn.connection.dbapi_connection eq_( testing.db.dialect.get_isolation_level(dbapi_conn), @@ -161,7 +161,7 @@ class DialectWBackendTest(fixtures.TestBase): # test that we can use isolation level setting and that it # reverts for "real" back to READ COMMITTED even though we # can't read it - dbapi_conn = conn.connection.connection + dbapi_conn = conn.connection.dbapi_connection conn = conn.execution_options(isolation_level="SERIALIZABLE") eq_( diff --git a/test/dialect/oracle/test_types.py b/test/dialect/oracle/test_types.py index 8302ed5233..799a5e7b65 100644 --- a/test/dialect/oracle/test_types.py +++ b/test/dialect/oracle/test_types.py @@ -1219,7 +1219,7 @@ class SetInputSizesTest(fixtures.TestBase): # invent a whole wrapping scheme def __init__(self, connection_fairy): - self.cursor = connection_fairy.connection.cursor() + self.cursor = connection_fairy.dbapi_connection.cursor() self.mock = mock.Mock() connection_fairy.info["mock"] = self.mock diff --git a/test/dialect/postgresql/test_async_pg_py3k.py b/test/dialect/postgresql/test_async_pg_py3k.py index 4ccc847dcc..d9116a7cec 100644 --- a/test/dialect/postgresql/test_async_pg_py3k.py +++ b/test/dialect/postgresql/test_async_pg_py3k.py @@ -268,7 +268,7 @@ class AsyncPgTest(fixtures.TestBase): engine = async_testing_engine() with mock.patch.object(engine.dialect, methname) as codec_meth: conn = await engine.connect() - adapted_conn = (await conn.get_raw_connection()).connection + adapted_conn = (await conn.get_raw_connection()).dbapi_connection await conn.close() eq_(codec_meth.mock_calls, [mock.call(adapted_conn)]) diff --git a/test/engine/test_deprecations.py b/test/engine/test_deprecations.py index 8f0a4b0229..5b723b8718 100644 --- a/test/engine/test_deprecations.py +++ b/test/engine/test_deprecations.py @@ -282,31 +282,30 @@ def MockDBAPI(): # noqa return db -class PoolTestBase(fixtures.TestBase): - def setup_test(self): - pool.clear_managers() - self._teardown_conns = [] - - def teardown_test(self): - for ref in self._teardown_conns: - conn = ref() - if conn: - conn.close() +class PoolTest(fixtures.TestBase): + def test_connection_rec_connection(self): + dbapi = MockDBAPI() + p1 = pool.Pool(creator=lambda: dbapi.connect("foo.db")) - @classmethod - def teardown_test_class(cls): - pool.clear_managers() + rec = pool._ConnectionRecord(p1) - def _queuepool_fixture(self, **kw): - dbapi, pool = self._queuepool_dbapi_fixture(**kw) - return pool + with expect_deprecated( + "The _ConnectionRecord.connection attribute is deprecated; " + "please use 'driver_connection'" + ): + is_(rec.connection, rec.dbapi_connection) - def _queuepool_dbapi_fixture(self, **kw): + def test_connection_fairy_connection(self): dbapi = MockDBAPI() - return ( - dbapi, - pool.QueuePool(creator=lambda: dbapi.connect("foo.db"), **kw), - ) + p1 = pool.QueuePool(creator=lambda: dbapi.connect("foo.db")) + + fairy = p1.connect() + + with expect_deprecated( + "The _ConnectionFairy.connection attribute is deprecated; " + "please use 'driver_connection'" + ): + is_(fairy.connection, fairy.dbapi_connection) def select1(db): diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 7f2dd434c3..2bbb976a84 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -198,7 +198,6 @@ class PoolTest(PoolTestBase): assert not r1.dbapi_connection c1 = r1.get_connection() is_(c1, r1.dbapi_connection) - is_(c1, r1.connection) is_(c1, r1.driver_connection) def test_rec_close_reopen(self): @@ -319,13 +318,11 @@ class PoolTest(PoolTestBase): is_not_none(rec.dbapi_connection) - is_(rec.connection, rec.dbapi_connection) is_(rec.driver_connection, rec.dbapi_connection) fairy = pool._ConnectionFairy(p1, rec.dbapi_connection, rec, False) is_not_none(fairy.dbapi_connection) - is_(fairy.connection, fairy.dbapi_connection) is_(fairy.driver_connection, fairy.dbapi_connection) is_(fairy.dbapi_connection, rec.dbapi_connection) @@ -349,32 +346,16 @@ class PoolTest(PoolTestBase): assert rec.dbapi_connection is not None is_not_none(rec.dbapi_connection) - is_(rec.connection, rec.dbapi_connection) is_(rec.driver_connection, mock_dc) fairy = pool._ConnectionFairy(p1, rec.dbapi_connection, rec, False) is_not_none(fairy.dbapi_connection) - is_(fairy.connection, fairy.dbapi_connection) is_(fairy.driver_connection, mock_dc) is_(fairy.dbapi_connection, rec.dbapi_connection) is_(fairy.driver_connection, mock_dc) - def test_connection_setter(self): - dbapi = MockDBAPI() - p1 = pool.Pool(creator=lambda: dbapi.connect("foo.db")) - - rec = pool._ConnectionRecord(p1) - - is_not_none(rec.dbapi_connection) - - is_(rec.connection, rec.dbapi_connection) - rec.connection = 42 - is_(rec.connection, rec.dbapi_connection) - rec.dbapi_connection = 99 - is_(rec.connection, rec.dbapi_connection) - class PoolDialectTest(PoolTestBase): def _dialect(self): diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 696391512e..c1e93bfd5d 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -552,11 +552,11 @@ class TransactionTest(fixtures.TablesTest): with eng.connect() as conn: rec = conn.connection._connection_record - raw_dbapi_con = rec.connection + raw_dbapi_con = rec.dbapi_connection conn.begin_twophase() conn.execute(users.insert(), dict(user_id=1, user_name="user1")) - assert rec.connection is raw_dbapi_con + assert rec.dbapi_connection is raw_dbapi_con with eng.connect() as conn: result = conn.execute( diff --git a/test/requirements.py b/test/requirements.py index ba256c4dd7..f7753fbf78 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -1437,7 +1437,7 @@ class DefaultRequirements(SuiteRequirements): if config.db.dialect._dbapi_version() < (4, 0, 19): return False with config.db.connect() as conn: - drivername = conn.connection.connection.getinfo( + drivername = conn.connection.driver_connection.getinfo( config.db.dialect.dbapi.SQL_DRIVER_NAME ) # on linux this is something like 'libmsodbcsql-13.1.so.9.2'.