slackapi / slackapi/python-slack-sdk

SlackApiError cannot be unpickled

オープン
#1,291 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

auto-triage-skip enhancement question web-client
主要言語
Python
スター
4k
フォーク
857
平均マージ
22時間 21分
マージ済み PR(30日)
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}"

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

SlackApiError の定義から始め、issue に示されている pickle の再現を Python 3.11 で実行します。例外がどのように初期化され、表現されるかを確認し、その後、pickling と unpickling によってメッセージとレスポンスが保持され、TypeError が発生しないことを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。