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
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,
# 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),
# 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_(
# 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
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)])
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):
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):
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)
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):
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(
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'.