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 --- test/sql/test_resultset.py | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'test/sql') diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py index 41bb81200..0537dc228 100644 --- a/test/sql/test_resultset.py +++ b/test/sql/test_resultset.py @@ -4,7 +4,11 @@ from contextlib import contextmanager import csv from io import StringIO import operator +import os import pickle +import subprocess +import sys +from tempfile import mkstemp from unittest.mock import Mock from unittest.mock import patch @@ -502,25 +506,25 @@ class CursorResultTest(fixtures.TablesTest): lambda: result[0]._mapping[addresses.c.address_id], ) - # @testing.variation("use_labels", [True, False]) - # def _dont_test_pickle_rows_other_process(self, connection, use_labels): - # result = self._pickle_row_data(connection, use_labels) - - # f, name = mkstemp("pkl") - # with os.fdopen(f, "wb") as f: - # pickle.dump(result, f) - # name = name.replace(os.sep, "/") - # code = ( - # "import sqlalchemy; import pickle; print([" - # f"r[0] for r in pickle.load(open('''{name}''', 'rb'))])" - # ) - # proc = subprocess.run( - # [sys.executable, "-c", code], stdout=subprocess.PIPE - # ) - # exp = str([r[0] for r in result]).encode() - # eq_(proc.returncode, 0) - # eq_(proc.stdout.strip(), exp) - # os.unlink(name) + @testing.variation("use_labels", [True, False]) + def test_pickle_rows_other_process(self, connection, use_labels): + result = self._pickle_row_data(connection, use_labels) + + f, name = mkstemp("pkl") + with os.fdopen(f, "wb") as f: + pickle.dump(result, f) + name = name.replace(os.sep, "/") + code = ( + "import sqlalchemy; import pickle; print([" + f"r[0] for r in pickle.load(open('''{name}''', 'rb'))])" + ) + proc = subprocess.run( + [sys.executable, "-c", code], stdout=subprocess.PIPE + ) + exp = str([r[0] for r in result]).encode() + eq_(proc.returncode, 0) + eq_(proc.stdout.strip(), exp) + os.unlink(name) def test_column_error_printing(self, connection): result = connection.execute(select(1)) -- cgit v1.2.1