Add getnewargs_ex to Enum base class to fix Ray serialization error
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 48/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- backend-api-design
Rechercherichtung
Finde die betterproto-Basisklasse Enum und reproduziere den Ray-Serialisierungsfehler mit dem im Issue gezeigten Event-Beispiel. Überprüfe die Änderung, indem du ein Enum-Mitglied über Ray serialisierst und deserialisierst, ohne einen benutzerdefinierten Serializer zu registrieren, und bestätige, dass der TypeError von Enum.new() nicht mehr auftritt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 235
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus danielgtaylor/python-betterproto
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
-
bug investigation needed
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 42/100
-
bug investigation needed
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
-
bug investigation needed
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 38/100
danielgtaylor/python-betterproto#676 · 3 Kommentare ·
Alle Issues in danielgtaylor/python-betterproto
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
AstrBotDevs/AstrBot#10720 ·
Maintainer antworten meist innerhalb von 1 Tag
-
fix(xiaomi): curated picker list still offers six ids that return 400 (plan-limited vs retired)Offencause/upstream comp/cli P2 provider/other tool/file type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
NousResearch/hermes-agent#143900 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 85/100
WLAN-Pi/wlanpi-profiler#341 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Maintainer antworten meist innerhalb von 1 Tag