slackapi / slackapi/python-slack-sdk
SlackApiError cannot be unpickled
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 4k
- Forks
- 857
- Ø Merge
- 22 Std. 21 Min.
- Gemergte PRs (30 T.)
- 16
Beschreibung
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}"
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Definition von SlackApiError und führe die im Issue gezeigte pickle-Reproduktion unter Python 3.11 aus. Prüfe, wie die Exception initialisiert und dargestellt wird, und verifiziere anschließend, dass Pickling und Unpickling die Nachricht und die Response beibehalten, ohne TypeError auszulösen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100