diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-24 13:54:37 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-02-24 13:54:37 -0500 |
commit | 5d42051c2e575713ffb8ea4f43ef1c2145b83c97 (patch) | |
tree | c6a863de5a20bd6e67cd160c229f0aa06347f66e | |
parent | 955f4a27c37ba73901745b89eb555eb8681d4b9f (diff) | |
download | sqlalchemy-5d42051c2e575713ffb8ea4f43ef1c2145b83c97.tar.gz |
Deprecate row.keys() for 2.0, not 1.x
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
-rw-r--r-- | lib/sqlalchemy/engine/row.py | 7 | ||||
-rw-r--r-- | test/sql/test_deprecations.py | 5 | ||||
-rw-r--r-- | test/sql/test_resultset.py | 10 |
3 files changed, 15 insertions, 7 deletions
diff --git a/lib/sqlalchemy/engine/row.py b/lib/sqlalchemy/engine/row.py index b4347a598..55d8c2249 100644 --- a/lib/sqlalchemy/engine/row.py +++ b/lib/sqlalchemy/engine/row.py @@ -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() ", ) diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py index 8bdba2793..06fe22fed 100644 --- a/test/sql/test_deprecations.py +++ b/test/sql/test_deprecations.py @@ -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"]) diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 2a6851a99..87886c4fa 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -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]""" |