Add getnewargs_ex to Enum base class to fix Ray serialization error
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- python
- Domínio
- backend-api-design
Direção de pesquisa
Localize a classe base Enum do betterproto e reproduza a falha de serialização do Ray com o exemplo Event mostrado na issue. Verifique a alteração serializando e desserializando um membro de Enum por meio do Ray sem registrar um serializador personalizado e confirme que o TypeError de Enum.new() não ocorre mais.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 1.8k
- Forks
- 235
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de danielgtaylor/python-betterproto
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 15/100
-
bug investigation needed
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 42/100
-
bug investigation needed
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 45/100
-
bug investigation needed
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 38/100
danielgtaylor/python-betterproto#676 · 3 comentários ·
Todas as issues de danielgtaylor/python-betterproto
Issues semelhantes
-
Project submission:Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
slavakurilyak/awesome-ai-agents#845 ·
Mantenedores costumam responder em até 1 dia
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directoryTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertadifficulty:2 enhancement good first issue
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 92/100
MakazhanAlpamys/Soup#2178 ·
Mantenedores costumam responder em até 1 dia
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
scverse/rapids-singlecell#854 ·
Mantenedores costumam responder em até 1 dia
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGLTalvez já em andamento @ninglinLiu assumiu há 1 dia. Abertaarea:frontend backend:slang bug direction:input
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
Mantenedores costumam responder em até 1 dia
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=FalseTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 13 dias