diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2023-03-07 00:25:59 +0100 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-10 10:26:26 -0500 |
| commit | fd9aa847920b9e4dff61ef7a5555c9fa6e362484 (patch) | |
| tree | 9dc0046bd234cbf4ad2aadef658283787c6e107b /test/base | |
| parent | 9c0715181de6f03543c7ac9038c481f57f773d49 (diff) | |
| download | sqlalchemy-fd9aa847920b9e4dff61ef7a5555c9fa6e362484.tar.gz | |
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
Diffstat (limited to 'test/base')
| -rw-r--r-- | test/base/test_result.py | 33 | ||||
| -rw-r--r-- | test/base/test_utils.py | 5 |
2 files changed, 25 insertions, 13 deletions
diff --git a/test/base/test_result.py b/test/base/test_result.py index 3e6444daa..6e7e53c21 100644 --- a/test/base/test_result.py +++ b/test/base/test_result.py @@ -195,35 +195,48 @@ class ResultTupleTest(fixtures.TestBase): eq_(kt._asdict(), {"a": 1, "b": 3}) @testing.requires.cextensions - def test_serialize_cy_py_cy(self): - from sqlalchemy.engine._py_row import BaseRow as _PyRow - from sqlalchemy.cyextension.resultproxy import BaseRow as _CyRow + @testing.variation("direction", ["py_to_cy", "cy_to_py"]) + def test_serialize_cy_py_cy(self, direction: testing.Variation): + from sqlalchemy.engine import _py_row + from sqlalchemy.cyextension import resultproxy as _cy_row global Row - p = result.SimpleResultMetaData(["a", None, "b"]) + p = result.SimpleResultMetaData(["a", "w", "b"]) + + if direction.py_to_cy: + dump_cls = _py_row.BaseRow + num = _py_row.KEY_INTEGER_ONLY + load_cls = _cy_row.BaseRow + elif direction.cy_to_py: + dump_cls = _cy_row.BaseRow + num = _cy_row.KEY_INTEGER_ONLY + load_cls = _py_row.BaseRow + else: + direction.fail() for loads, dumps in picklers(): - class Row(_CyRow): + class Row(dump_cls): pass - row = Row(p, p._processors, p._keymap, 0, (1, 2, 3)) + row = Row(p, p._processors, p._keymap, num, (1, 2, 3)) state = dumps(row) - class Row(_PyRow): + class Row(load_cls): pass row2 = loads(state) - is_true(isinstance(row2, _PyRow)) + is_true(isinstance(row2, load_cls)) + is_false(isinstance(row2, dump_cls)) state2 = dumps(row2) - class Row(_CyRow): + class Row(dump_cls): pass row3 = loads(state2) - is_true(isinstance(row3, _CyRow)) + is_true(isinstance(row3, dump_cls)) class ResultTest(fixtures.TestBase): diff --git a/test/base/test_utils.py b/test/base/test_utils.py index b979d43bc..01877f776 100644 --- a/test/base/test_utils.py +++ b/test/base/test_utils.py @@ -2458,9 +2458,8 @@ class SymbolTest(fixtures.TestBase): s = pickle.dumps(sym1) pickle.loads(s) - for protocol in 0, 1, 2: - print(protocol) - serial = pickle.dumps(sym1) + for _, dumper in picklers(): + serial = dumper(sym1) rt = pickle.loads(serial) assert rt is sym1 assert rt is sym2 |
