]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Deprecate row.keys() for 2.0, not 1.x
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Feb 2020 18:54:37 +0000 (13:54 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 24 Feb 2020 18:54:37 +0000 (13:54 -0500)
row.keys() is used by any use case that applies dict() to
a row.  Access of elements by string key is also a 2.0 deprecation
not 1.4 so for rudimental dict(row) support make sure that is all
a 2.0 thing.

Fixes current Alembic test suite.

Change-Id: I895496324133d615676cd76bc5f2c5f4a83e9131

lib/sqlalchemy/engine/row.py
test/sql/test_deprecations.py
test/sql/test_resultset.py

index b4347a5988de32de4e0e1e99ced87001ed5ca67a..55d8c2249dce29b02a6e5719e7965381caf4290b 100644 (file)
@@ -222,10 +222,9 @@ class Row(BaseRow, collections_abc.Sequence):
     def __repr__(self):
         return repr(sql_util._repr_row(self))
 
-    @util.deprecated(
-        "1.4",
-        "The :meth:`.Row.keys` method is deprecated and will be removed in a "
-        "future release.  Use the namedtuple standard accessor "
+    @util.deprecated_20(
+        ":meth:`.Row.keys`",
+        alternative="Use the namedtuple standard accessor "
         ":attr:`.Row._fields`, or for full mapping behavior use  "
         "row._mapping.keys() ",
     )
index 8bdba279313997d7c9e610e76397ea8398bad184..06fe22fed28de73fa419eac91e3d06d18d8bf854 100644 (file)
@@ -1582,9 +1582,8 @@ class ResultProxyTest(fixtures.TablesTest):
             text("select * from users where user_id=2")
         ).first()
 
-        with testing.expect_deprecated(
-            r"The Row.keys\(\) method is deprecated and will be "
-            "removed in a future release."
+        with testing.expect_deprecated_20(
+            r"The Row.keys\(\) function/method is considered legacy "
         ):
             eq_(r.keys(), ["user_id", "user_name"])
 
index 2a6851a99fbfa676aad6a3e6daa1d62b1fe6e553..87886c4faf0ddb458e2a71480c34a68f8d9e81d3 100644 (file)
@@ -1030,6 +1030,16 @@ class ResultProxyTest(fixtures.TablesTest):
         eq_(list(row._mapping.keys()), ["user_id", "user_name"])
         eq_(row._fields, ("user_id", "user_name"))
 
+    def test_row_keys_legacy_dont_warn(self):
+        users = self.tables.users
+
+        users.insert().execute(user_id=1, user_name="foo")
+        result = users.select().execute()
+        row = result.first()
+        # DO NOT WARN DEPRECATED IN 1.x, ONLY 2.0 WARNING
+        eq_(dict(row), {"user_id": 1, "user_name": "foo"})
+        eq_(row.keys(), ["user_id", "user_name"])
+
     def test_keys_anon_labels(self):
         """test [ticket:3483]"""