Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add getnewargs_ex to Enum base class to fix Ray serialization error

オープン
#658 コメント 5 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python

調査の方向性

betterproto の基底 Enum クラスを特定し、issue に示されている Event の例を使って Ray のシリアライズ失敗を再現します。カスタムシリアライザーを登録せずに、Enum メンバーを Ray 経由でシリアライズおよびデシリアライズして変更を検証し、Enum.new() の TypeError が発生しなくなったことを確認します。

索引モデルが issue の本文から書いたものです。

説明

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.
主要言語
Python
スター
1.8k
フォーク
235
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

danielgtaylor/python-betterproto のほかの issue

danielgtaylor/python-betterproto の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。