]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add deprecation for base Executable.bind
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Oct 2020 16:03:11 +0000 (12:03 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Oct 2020 23:15:58 +0000 (19:15 -0400)
These attributes will be removed in SQLAlchemy 2.0.

Also alters the deprecation message to qualify the
type of object correctly.  this in turn requires changes
in the warnings filter and deprecation tests.

Change-Id: I5779d9813e88f42e5db0c7b5e3ffff1d1535c203

13 files changed:
lib/sqlalchemy/sql/base.py
lib/sqlalchemy/sql/selectable.py
lib/sqlalchemy/testing/warnings.py
lib/sqlalchemy/util/deprecations.py
test/engine/test_deprecations.py
test/engine/test_execute.py
test/orm/inheritance/test_concrete.py
test/orm/inheritance/test_poly_linked_list.py
test/orm/inheritance/test_polymorphic_rel.py
test/orm/inheritance/test_relationship.py
test/orm/inheritance/test_single.py
test/orm/test_deprecations.py
test/sql/test_deprecations.py

index ba1107eac282a09a6b0d62b31f7111953af70a2c..4175fe89aa9909cb4d0bf061d4cf48eac6495202 100644 (file)
@@ -904,6 +904,10 @@ class Executable(Generative):
         return self.execute(*multiparams, **params).scalar()
 
     @property
+    @util.deprecated_20(
+        ":attr:`.Executable.bind`",
+        alternative="Bound metadata is being removed as of SQLAlchemy 2.0.",
+    )
     def bind(self):
         """Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
         to
index eebf3b96eaae5db7127944681c70b85c9cc7d41c..0e88a899910b93bc79d2bf56fa74399dd61bd613 100644 (file)
@@ -1221,7 +1221,14 @@ class Join(roles.DMLTableRole, FromClause):
         ).select_from(self)
 
     @property
+    @util.deprecated_20(
+        ":attr:`.Executable.bind`",
+        alternative="Bound metadata is being removed as of SQLAlchemy 2.0.",
+    )
     def bind(self):
+        """Return the bound engine associated with either the left or right
+        side of this :class:`_sql.Join`."""
+
         return self.left.bind or self.right.bind
 
     @util.preload_module("sqlalchemy.sql.util")
@@ -3487,7 +3494,15 @@ class CompoundSelect(HasCompileState, GenerativeSelect):
         return self.selects[0].selected_columns
 
     @property
+    @util.deprecated_20(
+        ":attr:`.Executable.bind`",
+        alternative="Bound metadata is being removed as of SQLAlchemy 2.0.",
+    )
     def bind(self):
+        """Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
+        to which this :class:`.Executable` is bound, or None if none found.
+
+        """
         if self._bind:
             return self._bind
         for s in self.selects:
@@ -5348,7 +5363,15 @@ class Select(
         return CompoundSelect._create_intersect_all(self, other, **kwargs)
 
     @property
+    @util.deprecated_20(
+        ":attr:`.Executable.bind`",
+        alternative="Bound metadata is being removed as of SQLAlchemy 2.0.",
+    )
     def bind(self):
+        """Returns the :class:`_engine.Engine` or :class:`_engine.Connection`
+        to which this :class:`.Executable` is bound, or None if none found.
+
+        """
         if self._bind:
             return self._bind
 
index 8ccb6516aa1b5547cf0ac4fb2926034c6d73d193..f3eb2b135c4c6d1a56a1beaff4c1d77ab3bcdadc 100644 (file)
@@ -50,13 +50,13 @@ def setup_filters():
         #
         # Core execution
         #
-        r"The (?:Executable|Engine)\.(?:execute|scalar)\(\) function",
+        r"The (?:Executable|Engine)\.(?:execute|scalar)\(\) method",
         r"The current statement is being autocommitted using implicit "
         "autocommit,",
         r"The connection.execute\(\) method in SQLAlchemy 2.0 will accept "
         "parameters as a single dictionary or a single sequence of "
         "dictionaries only.",
-        r"The Connection.connect\(\) function/method is considered legacy",
+        r"The Connection.connect\(\) method is considered legacy",
         r".*DefaultGenerator.execute\(\)",
         r"The autoload parameter is deprecated and will be removed ",
         #
@@ -65,10 +65,11 @@ def setup_filters():
         #
         r"The MetaData.bind argument is deprecated",
         r"The ``bind`` argument for schema methods that invoke SQL ",
+        r"The Executable.bind attribute is considered legacy ",
         #
         # result sets
         #
-        r"The Row.keys\(\) function/method",
+        r"The Row.keys\(\) method",
         r"Using non-integer/slice indices on Row ",
         #
         # Core SQL constructs
@@ -106,18 +107,18 @@ def setup_filters():
         #
         # ORM Query
         #
-        r"The Query\.get\(\) function",
-        r"The Query\.from_self\(\) function",
-        r"The Query\.with_parent\(\) function",
-        r"The Query\.with_parent\(\) function",
-        r"The Query\.select_entity_from\(\) function",
+        r"The Query\.get\(\) method",
+        r"The Query\.from_self\(\) method",
+        r"The Query\.with_parent\(\) method",
+        r"The Query\.with_parent\(\) method",
+        r"The Query\.select_entity_from\(\) method",
         r"The ``aliased`` and ``from_joinpoint`` keyword arguments",
         r"Using strings to indicate relationship names in Query.join",
         r"Using strings to indicate column or relationship paths in "
         "loader options",
         r"Using strings to indicate relationship names in the ORM "
         r"with_parent\(\)",
-        r"The Query.with_polymorphic\(\) function/method is considered "
+        r"The Query.with_polymorphic\(\) method is considered "
         "legacy as of the 1.x series",
         r"Passing a chain of multiple join conditions to Query.join\(\) "
         r"is deprecated and will be removed in SQLAlchemy 2.0.",
@@ -130,7 +131,7 @@ def setup_filters():
         r".*object is being merged into a Session along the backref "
         "cascade path",
         r"Passing bind arguments to Session.execute\(\) as keyword arguments",
-        r"The Session.transaction function/method",
+        r"The Session.transaction attribute",
         r"The merge_result\(\) method is superseded by the "
         r"merge_frozen_result\(\)",
         r"The Session.begin.subtransactions flag is deprecated",
index 83037bbff6e381e75cf9ca7a033e8d36a178204d..9f0ca0b1aa0e782254a2166c0dc4ae957c322a7f 100644 (file)
@@ -162,9 +162,17 @@ def moved_20(message, **kw):
 
 
 def deprecated_20(api_name, alternative=None, **kw):
+    type_reg = re.match("^:(attr|func|meth):", api_name)
+    if type_reg:
+        type_ = {"attr": "attribute", "func": "function", "meth": "method"}[
+            type_reg.group(1)
+        ]
+    else:
+        type_ = "construct"
     message = (
-        "The %s function/method is considered legacy as of the "
-        "1.x series of SQLAlchemy and will be removed in 2.0." % api_name
+        "The %s %s is considered legacy as of the "
+        "1.x series of SQLAlchemy and will be removed in 2.0."
+        % (api_name, type_)
     )
 
     if alternative:
index c2a98726f12136cd926f2dbf6a771d95deb83f29..322f9a942cab9b39acfd437f8967b30d110401d8 100644 (file)
@@ -91,7 +91,7 @@ class ConnectionlessDeprecationTest(fixtures.TestBase):
         conn = e.connect()
 
         with testing.expect_deprecated_20(
-            r"The Connection.connect\(\) function/method is considered",
+            r"The Connection.connect\(\) method is considered",
             r"The .close\(\) method on a so-called 'branched' connection is "
             r"deprecated as of 1.4, as are 'branched' connections overall, "
             r"and will be removed in a future release.",
@@ -108,13 +108,13 @@ class ConnectionlessDeprecationTest(fixtures.TestBase):
 
         stmt = table.insert().values(a=1)
         with testing.expect_deprecated_20(
-            r"The Engine.execute\(\) function/method is considered legacy",
+            r"The Engine.execute\(\) method is considered legacy",
         ):
             testing.db.execute(stmt)
 
         stmt = select(table)
         with testing.expect_deprecated_20(
-            r"The Engine.execute\(\) function/method is considered legacy",
+            r"The Engine.execute\(\) method is considered legacy",
         ):
             eq_(testing.db.execute(stmt).fetchall(), [(1,)])
 
@@ -125,13 +125,13 @@ class ConnectionlessDeprecationTest(fixtures.TestBase):
 
         stmt = table.insert().values(a=1)
         with testing.expect_deprecated_20(
-            r"The Executable.execute\(\) function/method is considered legacy",
+            r"The Executable.execute\(\) method is considered legacy",
         ):
             stmt.execute()
 
         stmt = select(table)
         with testing.expect_deprecated_20(
-            r"The Executable.execute\(\) function/method is considered legacy",
+            r"The Executable.execute\(\) method is considered legacy",
         ):
             eq_(stmt.execute().fetchall(), [(1,)])
 
@@ -581,7 +581,7 @@ class DeprecatedReflectionTest(fixtures.TablesTest):
         metadata = self.metadata
         table = Table("user", metadata)
         with testing.expect_deprecated_20(
-            r"The Inspector.reflecttable\(\) function/method is considered "
+            r"The Inspector.reflecttable\(\) method is considered "
         ):
             res = inspector.reflecttable(table, None)
         exp = inspector.reflect_table(table, None)
@@ -597,7 +597,7 @@ class ExecutionOptionsTest(fixtures.TestBase):
         c2 = conn.execution_options(foo="bar")
 
         with testing.expect_deprecated_20(
-            r"The Connection.connect\(\) function/method is considered "
+            r"The Connection.connect\(\) method is considered "
         ):
             c2_branch = c2.connect()
         eq_(c2_branch._execution_options, {"foo": "bar"})
index a1d6d2725ac6660b8ef52d62bfc66c6509ee9dc4..0ad9f6f4505ba562c69114d7d28b27e54a441b3a 100644 (file)
@@ -3292,7 +3292,7 @@ class FutureExecuteTest(fixtures.FutureEngineMixin, fixtures.TablesTest):
 
     def test_no_branching(self, connection):
         with testing.expect_deprecated(
-            r"The Connection.connect\(\) function/method is considered legacy"
+            r"The Connection.connect\(\) method is considered legacy"
         ):
             assert_raises_message(
                 NotImplementedError,
index 9b0a050d7ac60c39d510a4ab4b2060f77dae2ebf..e2777e9e9583d6d8295d3497c1b1a5ddc4fcc667 100644 (file)
@@ -577,9 +577,7 @@ class ConcreteTest(fixtures.MappedTest):
         # test adaption of the column by wrapping the query in a
         # subquery
 
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             eq_(
                 len(
                     session.connection()
@@ -593,9 +591,7 @@ class ConcreteTest(fixtures.MappedTest):
                 ),
                 2,
             )
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             eq_(
                 set(
                     [
index 266fb4b10ca5d18ff799296cd85aa119157754b0..83c3e75a00890f2f86cc512327bd688f8c14f391 100644 (file)
@@ -62,7 +62,7 @@ class PolymorphicCircularTest(fixtures.MappedTest):
         #   }, None, 'pjoin')
 
         with testing.expect_deprecated_20(
-            r"The Join.alias\(\) function/method is considered legacy"
+            r"The Join.alias\(\) method is considered legacy"
         ):
             join = table1.outerjoin(table2).outerjoin(table3).alias("pjoin")
             # join = None
index dd3ca4821caf530061c78b23b0e576f074c81641..51277943f0b6c2eb59e34f04f06040fca79a1361 100644 (file)
@@ -1553,9 +1553,7 @@ class _PolymorphicTestBase(object):
         palias = aliased(Person)
         expected = [(m1, e1), (m1, e2), (m1, b1)]
 
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             eq_(
                 sess.query(Person, palias)
                 .filter(Person.company_id == palias.company_id)
@@ -1575,9 +1573,7 @@ class _PolymorphicTestBase(object):
 
         expected = [(m1, e1), (m1, e2), (m1, b1)]
 
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             eq_(
                 sess.query(palias, palias2)
                 .filter(palias.company_id == palias2.company_id)
index 03fd05bd5c944f38bb1f9e79c09cdcbea61277f9..6879e146587bb083b144331da6f187f993766bcc 100644 (file)
@@ -1736,9 +1736,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
         # this query is coming out instead which is equivalent, but not
         # totally sure where this happens
 
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             self.assert_compile(
                 s.query(Sub2).from_self().join(Sub2.ep1).join(Sub2.ep2),
                 "SELECT anon_1.sub2_id AS anon_1_sub2_id, "
@@ -1789,9 +1787,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
         # I3abfb45dd6e50f84f29d39434caa0b550ce27864,
         # this query is coming out instead which is equivalent, but not
         # totally sure where this happens
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
 
             self.assert_compile(
                 # adding Sub2 to the entities list helps it,
index 65dd9c251e435e65ae3df216fba520cd40826b08..aa17f43007468d0eeb0b882de0964ac03284f12d 100644 (file)
@@ -284,9 +284,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
         Engineer = self.classes.Engineer
 
         sess = create_session()
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             self.assert_compile(
                 sess.query(Engineer).from_self(),
                 "SELECT anon_1.employees_employee_id AS "
@@ -423,9 +421,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
 
         sess = create_session()
         col = func.count(literal_column("*"))
-        with testing.expect_deprecated(
-            r"The Query.from_self\(\) function/method"
-        ):
+        with testing.expect_deprecated(r"The Query.from_self\(\) method"):
             self.assert_compile(
                 sess.query(Engineer.employee_id).from_self(col),
                 "SELECT count(*) AS count_1 "
index 7c87879d703cb30c083e20502f484b8a02c35a05..47e8041132e7884366f55dd3e74b7704bbbcdf36 100644 (file)
@@ -76,7 +76,7 @@ join_aliased_dep = (
 )
 
 w_polymorphic_dep = (
-    r"The Query.with_polymorphic\(\) function/method is "
+    r"The Query.with_polymorphic\(\) method is "
     "considered legacy as of the 1.x series"
 )
 
@@ -946,9 +946,7 @@ class SelfRefFromSelfTest(fixtures.MappedTest, AssertsCompiledSQL):
             )
 
     def _from_self_deprecated(self):
-        return testing.expect_deprecated_20(
-            r"The Query.from_self\(\) function/method"
-        )
+        return testing.expect_deprecated_20(r"The Query.from_self\(\) method")
 
 
 class DynamicTest(_DynamicFixture, _fixtures.FixtureTest):
@@ -982,9 +980,7 @@ class FromSelfTest(QueryTest, AssertsCompiledSQL):
     __dialect__ = "default"
 
     def _from_self_deprecated(self):
-        return testing.expect_deprecated_20(
-            r"The Query.from_self\(\) function/method"
-        )
+        return testing.expect_deprecated_20(r"The Query.from_self\(\) method")
 
     def test_illegal_operations(self):
 
@@ -1826,9 +1822,7 @@ class FromSelfTest(QueryTest, AssertsCompiledSQL):
 
 class SubqRelationsFromSelfTest(fixtures.DeclarativeMappedTest):
     def _from_self_deprecated(self):
-        return testing.expect_deprecated_20(
-            r"The Query.from_self\(\) function/method"
-        )
+        return testing.expect_deprecated_20(r"The Query.from_self\(\) method")
 
     @classmethod
     def setup_classes(cls):
index 176c16208ae90919f66972ed267683ba82a9386d..d566a1f6b7385df97e3554154722ecaf1468dae7 100644 (file)
@@ -724,7 +724,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL):
         j1 = self.table1.join(self.table2)
 
         with testing.expect_deprecated_20(
-            r"The Join.alias\(\) function/method is considered legacy"
+            r"The Join.alias\(\) method is considered legacy"
         ):
             self.assert_compile(
                 j1.alias(),
@@ -737,7 +737,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL):
             )
 
         with testing.expect_deprecated_20(
-            r"The Join.alias\(\) function/method is considered legacy"
+            r"The Join.alias\(\) method is considered legacy"
         ):
             self.assert_compile(
                 j1.alias(flat=True),
@@ -769,7 +769,7 @@ class SelectableTest(fixtures.TestBase, AssertsCompiledSQL):
         # test alias of the join
 
         with testing.expect_deprecated(
-            r"The Join.alias\(\) function/method is considered legacy"
+            r"The Join.alias\(\) method is considered legacy"
         ):
             j2 = jjj.alias("foo")
             assert (
@@ -1589,7 +1589,7 @@ class CursorResultTest(fixtures.TablesTest):
         ).first()
 
         with testing.expect_deprecated_20(
-            r"The Row.keys\(\) function/method is considered legacy "
+            r"The Row.keys\(\) method is considered legacy "
         ):
             eq_(r.keys(), ["user_id", "user_name"])