slackapi / slackapi/python-slack-sdk
SlackApiError cannot be unpickled
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 4k
- Forks
- 857
- Merge medio
- 22 h 21 min
- PR fusionados (30 d)
- 16
Descripción
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}"
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la definición de SlackApiError y ejecuta en Python 3.11 la reproducción con pickle mostrada en el issue. Comprueba cómo se inicializa y representa la excepción y, a continuación, verifica que el pickling y el unpickling conserven el mensaje y la respuesta sin generar TypeError.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100