Pickling errors with tz.FixedOffsetTimezone

"Lawrence Oluyede" <[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Message-ID <[email protected]>
I have a web application that uses memcached to store some data.
Some of that data is retrieved through psycopg2 (2.0.8) and contains
datetime instances.

Sometimes I get the following exception while trying to put objects
into the memcached cache:
"PicklingError: Can't pickle <class
'psycopg2.tz.FixedOffsetTimezone'>: it's not the same object as
psycopg2.tz.FixedOffsetTimezone"

I googled it and the only result I got is from a thread in the Django
mailing list confirming my suspicions.

It seems there's some identity problem with the class associated to
the datetime pickled instance.

I read the source code of the pickle module
<http://svn.python.org/view/python/trunk/Lib/pickle.py?view=markup>
and I found the place where the exception is raised in the save_global() method:

"""
    def save_global(self, obj, name=None, pack=struct.pack):
        write = self.write
        memo = self.memo

        if name is None:
            name = obj.__name__

        module = getattr(obj, "__module__", None)
        if module is None:
            module = whichmodule(obj, name)

        try:
            __import__(module)
            mod = sys.modules[module]
            klass = getattr(mod, name)
        except (ImportError, KeyError, AttributeError):
            raise PicklingError(
                "Can't pickle %r: it's not found as %s.%s" %
                (obj, module, name))
        else:
            if klass is not obj:
                raise PicklingError(
                    "Can't pickle %r: it's not the same object as %s.%s" %
                    (obj, module, name))

        ...
"""

whichmodule() basically looks for the module in sys.module but if the
class is not the same
it refuses to pickle.

Any ideas? It's a very strange error

-- 
Lawrence, http://oluyede.org - http://twitter.com/lawrenceoluyede
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.