slackapi / slackapi/python-slack-sdk
SlackApiError cannot be unpickled
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 4k
- 派生
- 857
- 平均合并
- 22 小时 21 分钟
- 30 天内合并 PR
- 16
描述
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}"
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 SlackApiError 的定义开始,在 Python 3.11 上运行 issue 中所示的 pickle 复现。检查异常的初始化和表示方式,然后验证 pickling 和 unpickling 能够保留消息和响应,且不会引发 TypeError。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100