This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author belopolsky
Recipients ajaksu2, alexandre.vassalotti, andersjm, belopolsky
Date 2010-06-29.17:10:54
SpamBayes Score 0.0012689886
Marked as misclassified No
Message-id <1277831456.3.0.517448676443.issue1581183@psf.upfronthosting.co.za>
In-reply-to
Content
Upon further investigation, I conclude that the problem is in the user code.  I am attaching int_subclass_pickle_problem_fixed.py 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.
History
Date User Action Args
2010-06-29 17:10:56belopolskysetrecipients: + belopolsky, andersjm, ajaksu2, alexandre.vassalotti
2010-06-29 17:10:56belopolskysetmessageid: <1277831456.3.0.517448676443.issue1581183@psf.upfronthosting.co.za>
2010-06-29 17:10:54belopolskylinkissue1581183 messages
2010-06-29 17:10:54belopolskycreate