slackapi / slackapi/python-slack-sdk
SlackApiError cannot be unpickled
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4k
- Forks
- 857
- Avg merge
- 22h 21m
- Merged PRs (30d)
- 16
Description
SlackApiError raises an error when trying to unpickle it.
This is particularly annoying in a Celery task since another bug in celery will cause the whole worker node to fail.
The Slack SDK version
2.9.4
Python runtime version
3.11.0
OS info
ProductName: macOS
ProductVersion: 13.0
BuildVersion: 22A380
Darwin Kernel Version 22.1.0: Sun Oct 9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000
Steps to reproduce:
import pickle
from slack.errors import SlackApiError
e = SlackApiError("Internal server error", "<response>")
dumped = pickle.dumps(e)
pickle.loads(dumped)
Expected result:
No error.
Actual result:
Traceback (most recent call last):
File "/private/tmp/pickle_exc/bug.py", line 7, in <module>
pickle.loads(dumped)
TypeError: SlackApiError.__init__() missing 1 required positional argument: 'response'
Solution
The SlackApiError could be implemented in such a way that the constructor accepts only the message, and the response defaults to None. Then the string representation can be delegated to __str__:
class SlackApiError(Exception):
def __init__(self, message, response=None):
super().__init__(message)
self.response = response
def __str__(self):
return f"{self.args[0]}\nThe server responded with: {self.response}"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the SlackApiError definition and run the pickle reproduction shown in the issue on Python 3.11. Check how the exception is initialized and represented, then verify that pickling and unpickling preserve the message and response without raising TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100