Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-103333: Pickle the keyword attributes of AttributeError#103352
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
csm10495 commented Apr 7, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Eclips4 commented Apr 7, 2023
Hello! |
csm10495 commented Apr 7, 2023
Sure, I'll write tests, update blurb once I know that this approach is likely to be accepted :) |
gaogaotiantian commented Apr 7, 2023
It won't be a rare case when the object is not picklable right? Won't that make a picklable Exception non-picklable with this change? |
csm10495 commented Apr 7, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
In theory yeah, if the object isn't picklable it would not work well here. Though this format follows in line with how other exceptions are made to be picklable (like OSError). Is there a way to somehow check if the obj, etc. are picklable and set them in that case (and if not, just leave as None (as it is now))? |
csm10495 commented Apr 7, 2023
I wonder if there should be some sort of pickle mode that pickles all it can and for the fields it couldn't pickle: set to |
gaogaotiantian commented Apr 7, 2023
I think |
csm10495 commented Apr 7, 2023
The original issue came from a user using AttributeError via multiprocessing and the .name attribute was lost via the pickle. .. maybe a middle ground is to just serialize .name and postpone the conversation on .obj? |
gaogaotiantian commented Apr 8, 2023
Having an Exception that loses attributes after pickling is definitely better than having one that is not picklable sometimes. Supporting pickling the |
csm10495 commented Apr 9, 2023
Updated PR to not pickle obj. Also updated a test to hit this change as well. |
iritkatriel commented Apr 9, 2023
CC @serhiy-storchaka re pickle. |
csm10495 commented Apr 15, 2023
@iritkatriel@serhiy-storchaka any chance for a merge or feedback? |
csm10495 commented Apr 21, 2023
@iritkatriel@serhiy-storchaka please provide feedback and/merge. Thanks. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot commented May 10, 2023
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
gpshead commented May 10, 2023
I left some comments, but I don't feel confident judging what changes to something that gets pickled are valid compatibility wise as I generally avoid use of pickle outside of tightly controlled scenarios. Will there be any compatibility issue with an AttributeError pickled by this PR being loaded in a Python process running an older Python version without this PR? |
csm10495 commented May 11, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@gpshead I updated based off your feedback. In terms of pickle-ability it works out well: Then in Python 3.11 I try to use the dumped pickle bytes: Then back in 3.12.0a7, using that pickle data works, albeit without the name field (which makes sense since the old Python doesn't pickle the field): Does this seem ok for merge now? |
erlend-aasland left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP-7 nits
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Erlend E. Aasland <[email protected]>
csm10495 commented May 12, 2023
Fixed nits. Thanks! |
iritkatriel commented May 13, 2023
There is a refleak now in this test, could it be this PR? |
iritkatriel commented May 13, 2023
See #104454 |
gh-103333: Pickle the keyword attributes of AttributeError
This should fix the case where pickling/unpickling an AttributeError loses the name/obj fields.
If this looks ok, I'd be happy to add a unit test, blurb, etc.