-
Notifications
You must be signed in to change notification settings - Fork 450
Open
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
- Programming language: Python
- OS: Linux
- Language runtime version: 3.12
- Package version: 1.24.0
Steps to reproduce
from google.genai.errors import APIError
import pickle
pickle.loads(pickle.dumps(APIError(1, {})))
This throws TypeError: APIError.__init__() missing 1 required positional argument: 'response_json'
A workaround for my use case is instead using a subclass like:
class PicklableAPIError(APIError):
def __reduce__(self):
state = self.__dict__.copy()
return (self._rebuild, (state,))
@staticmethod
def _rebuild(state):
obj = PicklableAPIError.__new__(PicklableAPIError)
obj.__dict__.update(state)
Exception.__init__(obj, f'{obj.code} {obj.status}. {obj.details}')
return obj
Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.