Add getnewargs_ex to Enum base class to fix Ray serialization error
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Localiza la clase base Enum de betterproto y reproduce el fallo de serialización de Ray con el ejemplo Event mostrado en el issue. Verifica el cambio serializando y deserializando un miembro de Enum mediante Ray sin registrar un serializador personalizado, y confirma que ya no se produce el TypeError de Enum.new().
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When using betterproto enums in a Ray environment, I encounter a pickling error when a task attempts to deserialize an enum member. For example, given an enum defined as follows:
class Event(betterproto.Enum):
START = 0
STOP = 1
and using this enum as part of a task’s arguments, I see the following error when deserializing:
ray.exceptions.RaySystemError: System error: Enum.__new__() takes 1 positional argument but 2 were given
This occurs during the call to ray.util.get_objects() (or similar), where Ray’s unpickler passes an extra argument to the Enum’s new method.
Workaround:
I found that manually registering serializers and deserializes for each enum (e.g., using:
ray.util.register_serializer(
Event,
serializer=lambda obj: obj.value,
deserializer=lambda value: Event(value),
)
solves the problem.
Proposed Solution:
The core issue seems to be that the default pickling mechanism for betterproto’s Enum (a subclass of IntEnum) is not handling the construction correctly in the Ray environment. The standard approach to helping pickle an enum instance correctly is implementing the getnewargs_ex method.
For example, adding the following method to the Enum base class:
def __getnewargs_ex__(self):
# Provide no positional arguments and the keyword arguments needed for __new__
return (), {"name": self.name, "value": self.value}
allows the default pickle protocol to serialize and deserialize the enum members properly. With this change, Ray’s deserialization will invoke the Enum’s new with the correct keyword arguments, avoiding the TypeError.
Additional Context:
- Environment: betterproto 2.0.0b7, Python 3.10 (with Ray)
Request:
- Would it be possible to incorporate a getnewargs_ex method in the base Enum class of betterproto? This would allow the standard pickle mechanism (and hence Ray’s object deserialization) to work without additional registration steps.
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 235
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de danielgtaylor/python-betterproto
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
-
bug investigation needed
Dificultad 3/5 1-2 días Aptitud para principiantes 42/100
-
bug investigation needed
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
-
bug investigation needed
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
danielgtaylor/python-betterproto#676 · 3 comentarios ·
Todos los issues de danielgtaylor/python-betterproto
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
zach-blumenfeld/aip#13 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
nathanmarlor/foxess_modbus#1287 ·
Los mantenedores suelen responder en 4 días
-
bug good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
OpenLakeForge/openlakeforge#498 ·
Los mantenedores suelen responder en 1 día
-
good first issue hacktoberfest help wanted python
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 1 día
-
Exact onnxruntime==1.27.0 core pin makes Pipecat-based apps uninstallable from the dashboardAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
pollen-robotics/reachy_mini#1493 ·
Los mantenedores suelen responder en 1 día