Skip to content

Conversation

@srilman
Copy link

@srilman srilman commented Nov 12, 2025

  • I understand that this repository is auto-generated and my pull request may not be merged

Changes being requested

Closes #2629. When working in a distributed environment, its useful to pickle and unpickle exceptions between workers. The default __reduce__ in Python does not account for keyword-only args, which is why we need to handle it ourselves.

Alternatively, we could modify the constructor of the exception classes to not use keyword-only args, but that was a larger change.

@srilman srilman requested a review from a team as a code owner November 12, 2025 02:17
@srilman srilman changed the title fix: pickle exceptions with custom reduce fix: pickle exceptions with custom __reduce__ Nov 12, 2025
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +126 to +132
@classmethod
def _reconstruct(cls, message: str, request: httpx.Request) -> Self:
return cls(message=message, request=request)

@override
def __reduce__(self) -> tuple[Callable[..., Self], tuple[Any, ...]]:
return (self.__class__._reconstruct, (self.message, self.request))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pickling APITimeoutError passes unsupported message arg

The new APIConnectionError.__reduce__ returns _reconstruct(self.message, self.request), which reconstructs the object via cls(message=message, request=request). APITimeoutError subclasses APIConnectionError but its __init__ takes only a request parameter and hard‑codes the message. Attempting to pickle an APITimeoutError will therefore raise TypeError: APITimeoutError.__init__() got an unexpected keyword argument 'message', defeating the goal of making these exceptions picklable. APITimeoutError needs its own __reduce__/reconstructor or _reconstruct must handle subclasses without a message parameter.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant