-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Allow pickling HTTPStatusError #3207
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
base: master
Are you sure you want to change the base?
Conversation
5f77774 to
f182a48
Compare
|
There is an earlier PR at #3108. We just need a maintainer to merge either of them. |
|
Hello, Apache Airflow maintainer here. We are facing the same issue: apache/airflow#47873 . We have adopted Would love for one of these or #3108 merged. |
|
@zanieb I don't know if it's inherently preferable, but I can explain why I wrote it that way. For a generic object, the default unpickle behavior is to call def __reduce__(self):
return (self.__class__.__new__, (self.__class__,), self.__dict__)However, BaseException defines a custom def __reduce__(self):
return (self.__class__, (self.args,), self.__dict__)So, for exceptions, My goal in this PR was to make unpickling work while keeping the behavior expected from exceptions. Therefore, I still call #3108 takes a different approach. It calls To sum up: this PR is more verbose, but less risky, because it hews closer to normal exception unpickling. If there is something that relies on exceptions calling However, you might instead make the judgement call that these subtle behavior changes are unlikely to be a problem with the exceptions that you have now, and go for the shorter solution in #3108. That's fine too, although I would still at least replace |
zanieb
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.
Great, thank you for taking the time to write that up in detail. This seems preferable to me.
|
(I can't unilaterally release this) |
|
I don't have merge permissions, either. Is there something else I need to do? Who has the merge button? |
|
I could merge it, but @tomchristie will need to weigh-in before it can be released regardless. |
|
This seems bizarrely inelegant to me. Overriding a magic method that I've never heard of prior to this issue, that's documented in stdlib with a warning. Seems like a gnarly code smell. It's not obvious that we should necessarily make exceptions pickleable. User code could choose to deal with that at a wrapping level. |
I disagree. I've had to do this before, use of If you're particularly opposed to this approach... maybe we should remove the keyword-only arguments from the exception type instead? Then it'd be pickleable without implementing |
💯 % agreed ! |
This fixes a few of bugs: * the timeout could sometimes be None when a float was expected * the async client didn't handle content-encoding correctly * I merged encode/httpx#3207 to make errors pickleable I also refactored stuff to extract common code between the async and sync code paths as much as I could. I added some tests here.
This fixes a few bugs: * the timeout could sometimes be None when a float was expected * the async client didn't handle content-encoding correctly * I merged encode/httpx#3207 to make errors pickleable I also refactored stuff to extract common code between the async and sync code paths as much as I could. I added some tests here.
|
Hello. Anything new about this? This issue prevents correct exception information from being retrieved in multi-process scenarios, resulting in something like Creating a custom type is possible, but without guidance on how to wrap it, some exception information may be lost, which may not be desirable. Also, while this may be a design issue within Python itself, Python's multi-process API is intended to provide a completely transparent interface. In theory, it is expected to be possible to use multi-process without modifying any other code. |
|
Any news on this? |
|
@lovelydinosaur in #3108 (comment) you asked if this could be implemented with
I think everyone would be happy with any of the following:
We're happy with any solution you prefer, as long as the tests in this PR pass. |
Summary
HTTPStatusError's
__init__method has required keyword-only arguments. BaseException has a custom__reduce__method that can't handle that correctly. As a result, attempting to unpickle a pickled HTTPStatusError fails with:This PR fixes that by defining an appropriate
__reduce__method for HTTPStatusError.Checklist
Note: I don't think this requires a documentation change, but let me know if so.