From fd9aa847920b9e4dff61ef7a5555c9fa6e362484 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Tue, 7 Mar 2023 00:25:59 +0100 Subject: Fix regression when deserializing python rows into cython Fixed regression involving pickling of Python rows between the cython and pure Python implementations of :class:`.Row`, which occurred as part of refactoring code for version 2.0 with typing. A particular constant were turned into a string based ``Enum`` for the pure Python version of :class:`.Row` whereas the cython version continued to use an integer constant, leading to deserialization failures. Regression occurred in a4bb502cf95ea3523e4d383c4377e50f402d7d52 Fixes: #9423 Change-Id: Icbd85cacb2d589cef7c246de7064249926146f2e --- lib/sqlalchemy/engine/_py_row.py | 5 ++++- lib/sqlalchemy/testing/util.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/engine/_py_row.py b/lib/sqlalchemy/engine/_py_row.py index 7cbac552f..1b952fe4c 100644 --- a/lib/sqlalchemy/engine/_py_row.py +++ b/lib/sqlalchemy/engine/_py_row.py @@ -24,7 +24,7 @@ if typing.TYPE_CHECKING: MD_INDEX = 0 # integer index in cursor.description -class _KeyStyle(enum.Enum): +class _KeyStyle(enum.IntEnum): KEY_INTEGER_ONLY = 0 """__getitem__ only allows integer values and slices, raises TypeError otherwise""" @@ -121,6 +121,9 @@ class BaseRow: mdindex = rec[MD_INDEX] if mdindex is None: self._parent._raise_for_ambiguous_column_name(rec) + # NOTE: keep "== KEY_OBJECTS_ONLY" instead of "is KEY_OBJECTS_ONLY" + # since deserializing the class from cython will load an int in + # _key_style, not an instance of _KeyStyle elif self._key_style == KEY_OBJECTS_ONLY and isinstance(key, int): raise KeyError(key) diff --git a/lib/sqlalchemy/testing/util.py b/lib/sqlalchemy/testing/util.py index 153ce4d0a..d061f26a2 100644 --- a/lib/sqlalchemy/testing/util.py +++ b/lib/sqlalchemy/testing/util.py @@ -59,7 +59,7 @@ def picklers(): # yes, this thing needs this much testing for pickle_ in picklers: - for protocol in range(-2, pickle.HIGHEST_PROTOCOL): + for protocol in range(-2, pickle.HIGHEST_PROTOCOL + 1): yield pickle_.loads, lambda d: pickle_.dumps(d, protocol) -- cgit v1.2.1