slackapi / slackapi/python-slack-sdk

SlackApiError cannot be unpickled

Đang mở
#1,291 6 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

auto-triage-skip enhancement question web-client
Ngôn ngữ chính
Python
Star
4k
Fork
857
Merge trung bình
22 giờ 21 phút
Pull request đã merge (30 ngày)
16

Mô tả

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}"

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với định nghĩa của SlackApiError và chạy bản tái hiện bằng pickle được nêu trong issue trên Python 3.11. Kiểm tra cách exception được khởi tạo và biểu diễn, sau đó xác minh rằng việc pickling và unpickling giữ nguyên message và response mà không gây ra TypeError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.