Unknown value for enum
まだ誰も着手していません。
評価
調査の方向性
betterproto/init.py の _from_dict_init から開始し、traceback に示されているとおり、その呼び出しを betterproto/enum.py の from_string まで追ってください。提供された protobuf と JSON を使って、enum が繰り返されるケースを再現し、文字列の処理を壊さずに from_json から数値の enum 値を正常にパースできることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Summary
Unknown value for enum error in from_json
Reproduction Steps
syntax = "proto3";
package hello;
enum Test {
TestUnset = 0;
Test1 = 1;
Test2 = 2;
}
message Greeting {
repeated Test test = 1;
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: test.proto
# plugin: python-betterproto
# This file has been @generated
from dataclasses import dataclass
from typing import (
List,
)
import betterproto
class Test(betterproto.Enum):
TestUnset = 0
Test1 = 1
Test2 = 2
@dataclass(eq=False, repr=False)
class Greeting(betterproto.Message):
test: List["Test"] = betterproto.enum_field(1)
import hello
JSON_STR = """
{
"test": [1]
}
"""
greeting = hello.Greeting().from_json(JSON_STR)
Expected Results
Should parse correct
Actual Results
File "/opt/homebrew/Caskroom/miniconda/base/envs/platform/lib/python3.12/site-packages/betterproto/__init__.py", line 1690, in from_json
return self.from_dict(json.loads(value))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/platform/lib/python3.12/site-packages/betterproto/__init__.py", line 1630, in from_dict
for field, value in self._from_dict_init(value).items():
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/platform/lib/python3.12/site-packages/betterproto/__init__.py", line 1581, in _from_dict_init
value = [enum_cls.from_string(e) for e in value]
^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/envs/platform/lib/python3.12/site-packages/betterproto/enum.py", line 202, in from_string
raise ValueError(f"Unknown value {name} for enum {cls.__name__}") from e
ValueError: Unknown value 1 for enum Test
System Information
libprotoc 29.3
Python 3.12.9
Name: betterproto
Version: 2.0.0b7
Summary: A better Protobuf / gRPC generator & library
Home-page: https://github.com/danielgtaylor/python-betterproto
Author: Daniel G. Taylor
Author-email: [email protected]
License: MIT
Location: /opt/homebrew/Caskroom/miniconda/base/envs/platform/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: platform-sdk
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 235
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
danielgtaylor/python-betterproto のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 15/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
bug investigation needed
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
bug investigation needed
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
danielgtaylor/python-betterproto#676 · コメント 3 件 ·
danielgtaylor/python-betterproto の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
volcengine/OpenViking#6445 ·
メンテナーはふだん 1 日以内に返信
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be edited対応中かも @ManyaJain111 が今日担当しました。 オープンbug enhancement possible-duplicate
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
AOSSIE-Org/PictoPy#1637 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
deepspeedai/DeepSpeed#8884 ·
メンテナーはふだん 3 日以内に返信
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
flagos-ai/FlagQuantum#718 ·
メンテナーはふだん 1 日以内に返信
-
bug CI-failure high priority
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
vllm-project/afd-plugin#483 ·
メンテナーはふだん 1 日以内に返信