Repository navigation
fix(google-api-core): make RetryError picklable and copyable - #18947
Open
Mahalaxmibejugam wants to merge 2 commits into
Open
Mahalaxmibejugam wants to merge 2 commits into
Mahalaxmibejugam wants to merge 2 commits into
Conversation
RetryError.__init__ requires a 'cause' argument that isn't stored in
self.args, so the default BaseException.__reduce__ rebuilds it as
RetryError(message) and fails with:
TypeError: RetryError.__init__() missing 1 required positional
argument: 'cause'
This breaks pickling (e.g. returning the error from multiprocessing or
concurrent.futures workers) as well as copy.copy/copy.deepcopy.
Define __reduce__ so the exception is rebuilt with both message and
cause.
Mahalaxmibejugam
marked this pull request as draft
November 1, 2026 19:36
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements the reduce method for exceptions to support proper pickling and copying across processes, and adds corresponding unit tests. The reviewer noted that returning only a 2-tuple from reduce will cause any additional instance attributes to be lost, and suggested returning self.dict as the third element to preserve them.
…ckling Return self.__dict__ as the state from RetryError.__reduce__, matching BaseException's default behavior, so attributes set on the instance (including notes added with add_note()) survive pickling and copying.
Mahalaxmibejugam
marked this pull request as ready for review
November 1, 2026 19:53
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18946 🦕
Problem
RetryError.__init__(self, message, cause)requirescause, but onlymessageis passed toException.__init__, soself.args == (message,). The defaultBaseException.__reduce__rebuilds the exception asRetryError(message), which fails:As a result, a
RetryErrorraised in a worker process can't be returned to the parent.multiprocessing.Poolresult handling crashes andAsyncResult.get()blocks, andProcessPoolExecutorraisesBrokenProcessPool.copy.copy()/copy.deepcopy()of aRetryErrorfail the same way.Fix
Define
RetryError.__reduce__so the exception is rebuilt with bothmessageandcause, and returnself.__dict__as the state (asBaseExceptiondoes by default) so other instance attributes, such as notes added withadd_note(), are preserved.Testing
Added unit tests in
tests/unit/test_exceptions.py:message,causeandstr()preserved);cause=None;copy.copyandcopy.deepcopy.The new tests fail without the fix and pass with it.
tests/unit/retryandtests/unit/test_exceptions.pypass (198 tests), andruff format --check/ruff checkare clean.