]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
deprecate .connection on _ConnectionFairy, _ConnectionRecord
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 22 May 2022 18:28:14 +0000 (14:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 22 May 2022 19:24:05 +0000 (15:24 -0400)
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

lib/sqlalchemy/pool/base.py
test/dialect/oracle/test_dialect.py
test/dialect/oracle/test_types.py
test/dialect/postgresql/test_async_pg_py3k.py
test/engine/test_deprecations.py
test/engine/test_pool.py
test/engine/test_transaction.py
test/requirements.py

index 22be96fad10260b0dcc04a5dc57363ffe7d3190e..51eb5e9f5e29f40a599f9bfc9eda6da84c442a36 100644 (file)
@@ -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,
index ad361b87941a25b4aa7f82009204065530681091..26a29b73e620837428156b43f646e51ac7ae64fc 100644 (file)
@@ -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_(
index 8302ed5233b85bf8fd89d264dea6cc1d59e383df..799a5e7b6571957c9b80b6fdbd2f7ecdb1a8bd6d 100644 (file)
@@ -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
 
index 4ccc847dcc5b7ca87e79fdfbacc131bc21c732c0..d9116a7cecc815d8c9809caff97ad0fb705c085c 100644 (file)
@@ -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)])
index 8f0a4b02294b02f172afcef0c3bd265d3d283cc1..5b723b87185e48afaeaec4156ad80dfbd6dd831a 100644 (file)
@@ -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):
index 7f2dd434c35d4fbea05caa6b8dba3f3312654528..2bbb976a84c50086d9ac07e5e8ee0c73958f6da3 100644 (file)
@@ -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):
index 696391512eb13acdfdb407e123e63667f42c4063..c1e93bfd5dcf3e7c53cd7edb55f2f9c3d3aa4efa 100644 (file)
@@ -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(
index ba256c4dd7c34d4a4aea44bcb895968508185e24..f7753fbf78001f02c7a7947f507d424f534c25aa 100644 (file)
@@ -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'.