]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Fix LegacyRow/Row index access
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2021 17:57:39 +0000 (13:57 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 8 Apr 2021 20:06:41 +0000 (16:06 -0400)
commitdca3a43de60b064d863abb9b86b1f629fbd4b14d
tree09d531c9e0a4b0178343d2942c0e7e6d7d2cf846
parent4d21920638af4729b6ff09b1ac8c3a20878bd922
Fix LegacyRow/Row index access

Fixed up the behavior of the :class:`_result.Row` object when dictionary
access is used upon it, meaning converting to a dict via ``dict(row)`` or
accessing members using strings or other objects i.e. ``row["some_key"]``
works as it would with a dictionary, rather than raising ``TypeError`` as
would be the case with a tuple, whether or not the C extensions are in
place. This was originally supposed to emit a 2.0 deprecation warning for
the "non-future" case using :class:`_result.LegacyRow`, and was to raise
``TypeError`` for the "future" :class:`_result.Row` class. However, the C
version of :class:`_result.Row` was failing to raise this ``TypeError``,
and to complicate matters, the :meth:`_orm.Session.execute` method now
returns :class:`_result.Row` in all cases to maintain consistency with the
ORM result case, so users who didn't have C extensions installed would
see different behavior in this one case for existing pre-1.4 style
code.

Therefore, in order to soften the overall upgrade scheme as most users have
not been exposed to the more strict behavior of :class:`_result.Row` up
through 1.4.6, :class:`_result.LegacyRow` and :class:`_result.Row` both
provide for string-key access as well as support for ``dict(row)``, in all
cases emitting the 2.0 deprecation warning when ``SQLALCHEMY_WARN_20`` is
enabled. The :class:`_result.Row` object still uses tuple-like behavior for
``__contains__``, which is probably the only noticeable behavioral change
compared to :class:`_result.LegacyRow`, other than the removal of
dictionary-style methods ``values()`` and ``items()``.

Also remove filters for result set warnings.

callcounts updated for 2.7/ 3.9, am pushing jenkins to use python 3.9
now

Fixes: #6218
Change-Id: Ia69b974f3dbc46943c57423f57ec82323c8ae63b
doc/build/changelog/unreleased_14/6218.rst [new file with mode: 0644]
lib/sqlalchemy/cextension/resultproxy.c
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/engine/row.py
lib/sqlalchemy/testing/warnings.py
regen_callcounts.tox.ini
test/dialect/oracle/test_types.py
test/orm/test_query.py
test/profiles.txt
test/sql/test_resultset.py