From 6a46c1068bf90faaf3b73024e8c48b04899a8e97 Mon Sep 17 00:00:00 2001 From: "Bradford D. Boyle" Date: Sun, 12 May 2024 20:39:07 -0700 Subject: [PATCH] Customize PostgreSQL class pickle serialization This commit modifies PostgreSQL to omit v_special when pickling. OmniDB is configured to use django's PickleSerializer but Python's pickle module can only serialize functions that are accessible from the top-level of a module. Newer version's of pgspecial use an inner function when creating SpecialCommands. This causes an AttributeError to be thrown with the following message: AttributeError: Can't pickle local object 'show_extra_help_command..placeholder' When an instance of PostgreSQL is deserialized, v_special is recreated. This approach works since v_special is only read and isn't modified. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1053100 https://docs.python.org/3/library/pickle.html#what-can-be-pickled-and-unpickled --- OmniDB/OmniDB_app/include/Spartacus/Database.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OmniDB/OmniDB_app/include/Spartacus/Database.py b/OmniDB/OmniDB_app/include/Spartacus/Database.py index a41281bc..4ec25a08 100644 --- a/OmniDB/OmniDB_app/include/Spartacus/Database.py +++ b/OmniDB/OmniDB_app/include/Spartacus/Database.py @@ -1859,6 +1859,16 @@ class PostgreSQL(Generic): if not v_keep: self.Close() + def __getstate__(self): + state = self.__dict__.copy() + # don't pickle 'v_special' + del state["v_special"] + return state + + def __setstate__(self, state): + self.__dict__.update(state) + # add 'v_special' back since it doesn't exist in the pickle + self.v_special = PGSpecial() ''' ------------------------------------------------------------------------ -- 2.45.2