gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Remove passing exception as args to super in APIError

Open mike-flowers-airbnb opened this issue 8 months ago • 13 comments

First, thanks for this tool!

We have a pipeline where exceptions from packages such as gspread are pickled and stored for further processing. Unfortunately, the APIError exception is not able to be unpickled as the args it passed to the Exception super are different from what is passed into the exception itself.

The sample test extension exposes this error as seen below:

    def __init__(self, response: Response):
        super().__init__(self._extract_error(response))
        self.response: Response = response
>       self.error: Mapping[str, Any] = response.json()["error"]
E       AttributeError: 'dict' object has no attribute 'json'

gspread/exceptions.py:45: AttributeError

This PR ultimately only replaces the extracted error with the raw response passed to the kwargs. Given that __str__ and __repr__ are overloaded and all other usage of this exception use the other members, there is no visible impact from this change.

mike-flowers-airbnb avatar Jun 05 '24 21:06 mike-flowers-airbnb