From: Mike Bayer Date: Mon, 12 Oct 2020 16:47:38 +0000 (-0400) Subject: Repair reduction in Over X-Git-Tag: rel_1_4_0b1~39^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9322de12f5c5eca397b13cb7db2b6196f58aceb3;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Repair reduction in Over Fixed issue where a plain pickle dumps call of the :class:`_sql.Over` construct didn't work. Fixes: #5644 Change-Id: I4b07f74ecd5d52f0794128585367012200a38a36 --- diff --git a/doc/build/changelog/unreleased_13/5644.rst b/doc/build/changelog/unreleased_13/5644.rst new file mode 100644 index 0000000000..d0e20492b8 --- /dev/null +++ b/doc/build/changelog/unreleased_13/5644.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, sql + :tickets: 5644 + + Fixed issue where a plain pickle dumps call of the :class:`_sql.Over` + construct didn't work. diff --git a/lib/sqlalchemy/sql/elements.py b/lib/sqlalchemy/sql/elements.py index c8ae1e6b64..5fb28f1d1a 100644 --- a/lib/sqlalchemy/sql/elements.py +++ b/lib/sqlalchemy/sql/elements.py @@ -3849,6 +3849,15 @@ class Over(ColumnElement): else: self.rows = self.range_ = None + def __reduce__(self): + return self.__class__, ( + self.element, + self.partition_by, + self.order_by, + self.range_, + self.rows, + ) + def _interpret_range(self, range_): if not isinstance(range_, tuple) or len(range_) != 2: raise exc.ArgumentError("2-tuple expected for range/rows") diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py index f9a8f998ed..1722a1e690 100644 --- a/test/sql/test_functions.py +++ b/test/sql/test_functions.py @@ -483,6 +483,21 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): except AttributeError: assert True + def test_pickle_over(self): + # TODO: the test/sql package lacks a comprehensive pickling + # test suite even though there are __reduce__ methods in several + # places in sql/elements.py. likely as part of + # test/sql/test_compare.py might be a place this can happen but + # this still relies upon a strategy for table metadata as we have + # in serializer. + + f1 = func.row_number().over() + + self.assert_compile( + util.pickle.loads(util.pickle.dumps(f1)), + "row_number() OVER ()", + ) + def test_functions_with_cols(self): users = table( "users", column("id"), column("name"), column("fullname")