From 303e753b2d674d89f8277e8cd06dd0acf7094549 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 4 Nov 2007 22:04:22 +0000 Subject: [PATCH] - func. objects can be pickled/unpickled [ticket:844] --- CHANGES | 2 ++ lib/sqlalchemy/sql/expression.py | 8 ++++++++ test/sql/select.py | 3 +++ 3 files changed, 13 insertions(+) diff --git a/CHANGES b/CHANGES index 1d8a5301a0..0a1a65730f 100644 --- a/CHANGES +++ b/CHANGES @@ -27,6 +27,8 @@ CHANGES executes inline as normal but will not trigger a "postfetch" condition for the column, for those DB's who provide it via cursor.lastrowid + - func. objects can be pickled/unpickled [ticket:844] + - orm - eager loading with LIMIT/OFFSET applied no longer adds the primary table joined to a limited subquery of itself; the eager loads now diff --git a/lib/sqlalchemy/sql/expression.py b/lib/sqlalchemy/sql/expression.py index 67c1b727a9..22c296e98b 100644 --- a/lib/sqlalchemy/sql/expression.py +++ b/lib/sqlalchemy/sql/expression.py @@ -2476,6 +2476,14 @@ class _ColumnElementAdapter(ColumnElement): def __getattr__(self, attr): return getattr(self.elem, attr) + def __getstate__(self): + return {'elem':self.elem, 'type':self.type, 'orig_set':self.orig_set} + + def __setstate__(self, state): + self.elem = state['elem'] + self.type = state['type'] + self.orig_set = state['orig_set'] + class _Grouping(_ColumnElementAdapter): """Represent a grouping within a column expression""" pass diff --git a/test/sql/select.py b/test/sql/select.py index ace4557027..1999b52a07 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -691,6 +691,9 @@ FROM mytable, myothertable WHERE foo.id = foofoo(lala) AND datetime(foo) = Today # test None becomes NULL self.assert_compile(func.my_func(1,2,None,3), "my_func(:my_func, :my_func_1, NULL, :my_func_2)") + # test pickling + self.assert_compile(util.pickle.loads(util.pickle.dumps(func.my_func(1, 2, None, 3))), "my_func(:my_func, :my_func_1, NULL, :my_func_2)") + # assert func raises AttributeError for __bases__ attribute, since its not a class # fixes pydoc try: -- 2.47.3