summaryrefslogtreecommitdiff
path: root/test/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-02-02 13:24:40 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-02-21 16:26:57 -0500
commit93b7767d00267ebe149cabcae7246b6796352eb8 (patch)
tree021f4960fccf4d6cc3cce17e680bdd6e8823d5c9 /test/sql
parent1e126829d594aa9f525c41942b2729bae9378fcd (diff)
downloadsqlalchemy-93b7767d00267ebe149cabcae7246b6796352eb8.tar.gz
Deprecate connection branching
The :meth:`.Connection.connect` method is deprecated as is the concept of "connection branching", which copies a :class:`.Connection` into a new one that has a no-op ".close()" method. This pattern is oriented around the "connectionless execution" concept which is also being removed in 2.0. As part of this change we begin to move the internals away from "connectionless execution" overall. Remove the "connectionless execution" concept from the reflection internals and replace with explicit patterns at the Inspector level. Fixes: #5131 Change-Id: Id23d28a9889212ac5ae7329b85136157815d3e6f
Diffstat (limited to 'test/sql')
-rw-r--r--test/sql/test_defaults.py7
-rw-r--r--test/sql/test_deprecations.py35
2 files changed, 36 insertions, 6 deletions
diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py
index b31b070d8..2fded335b 100644
--- a/test/sql/test_defaults.py
+++ b/test/sql/test_defaults.py
@@ -163,12 +163,7 @@ class DefaultTest(fixtures.TestBase):
def mydefault_using_connection(ctx):
conn = ctx.connection
- try:
- return conn.execute(sa.select([sa.text("12")])).scalar()
- finally:
- # ensure a "close()" on this connection does nothing,
- # since its a "branched" connection
- conn.close()
+ return conn.execute(sa.select([sa.text("12")])).scalar()
use_function_defaults = testing.against("postgresql", "mssql")
is_oracle = testing.against("oracle")
diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py
index b2b1f470b..b058cbe1b 100644
--- a/test/sql/test_deprecations.py
+++ b/test/sql/test_deprecations.py
@@ -1494,3 +1494,38 @@ class PositionalTextTest(fixtures.TablesTest):
"Could not locate column in row for column 'text1.b'",
lambda: row[text1.c.b],
)
+
+
+class DefaultTest(fixtures.TestBase):
+ __backend__ = True
+
+ @testing.provide_metadata
+ def test_close_on_branched(self):
+ metadata = self.metadata
+
+ def mydefault_using_connection(ctx):
+ conn = ctx.connection
+ try:
+ return conn.execute(select([text("12")])).scalar()
+ finally:
+ # ensure a "close()" on this connection does nothing,
+ # since its a "branched" connection
+ conn.close()
+
+ table = Table(
+ "foo",
+ metadata,
+ Column("x", Integer),
+ Column("y", Integer, default=mydefault_using_connection),
+ )
+
+ metadata.create_all(testing.db)
+ with testing.db.connect() as conn:
+ with testing.expect_deprecated(
+ r"The .close\(\) method on a so-called 'branched' "
+ r"connection is deprecated as of 1.4, as are "
+ r"'branched' connections overall"
+ ):
+ conn.execute(table.insert().values(x=5))
+
+ eq_(conn.execute(select([table])).first(), (5, 12))