New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pickle fails on BeautifulSoup's navigableString instances #45222
Comments
Trying to pickle an instance of BeautifulSoup's NavigableString class, this is the result: Diagnosis: The problem arises when trying to pickle such instances - pickle enters an endless loop and reaches the max recursion limit (eventually). This happens regardless of the protocol used. Possibly related to SF bug bpo-1581183: "pickle protocol 2 failure on int subclass" See http://mail.python.org/pipermail/idle-dev/2007-July/002600.html (originally a bug report for IDLE on the IDLE-dev list) for details (including how to recreate the error). Related IDLE bug report: bpo-1757057 |
I started by isolating the most minimalist code that triggers the error. As expected, this program fails with RuntimeError: maximum recursion
Initial call to dump(), as intended.
save() calls obj.__reduce_ex(), obj being our EvilString instance. This function is defined in copyreg.py, line 58 and following my
save_reduce() calls self.save() twice:
save() finds out its argument is a Tuple, and calls save_tuple()
... and save_tuple() calls save() on each element of the tuple. The problem lies in _reduce_ex(), in the definition of the state of the copyreg.py, lines 65 to 70: When this code gets executed on an EvilString instance, base is the type Which corresponds to unicode(self), or self.__unicode__, which returns I don't know if this is flaw in the design of _reduce_ex, or a flaw |
This is indeed tricky. The docs say __unicode__ "should return a Unicode Asking Neal for a second opinion. |
Closing as "won't fix". |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: