Author belopolsky
Recipients ajaksu2, alexandre.vassalotti, andersjm, belopolsky
Date 2010-06-29.17:10:54
SpamBayes Score 0.00126899
Marked as misclassified No
Message-id <>
Upon further investigation, I conclude that the problem is in the user code.  I am attaching which fixes the user code as follows:

     def __getnewargs__(self):
-        return (int(self), self.an_enum)
+        return (int(self), None)

Note that with this change, the object is pickled correctly because __setstate__ takes care of resetting self.an_enum.

The problem is that self-referential state should not be passed via __getnewargs__ mechanism.  This is because when pickler starts writing newargs, it is already committed to creating a new object (otherwise it would not need to serialize newargs in the first place.)  If the newargs contain the object that is being pickled, it will be serialized twice unless this situation is caught in memoize.

What can be improved, is the diagnostic and possibly documentation.  If after saving newargs, memo contains the object that is being pickled, an exception should be raised explaining that __getnewargs__() should not contain self-references.
Date User Action Args
2010-06-29 17:10:56belopolskysetrecipients: + belopolsky, andersjm, ajaksu2, alexandre.vassalotti
2010-06-29 17:10:56belopolskysetmessageid: <>
2010-06-29 17:10:54belopolskylinkissue1581183 messages
2010-06-29 17:10:54belopolskycreate