Unknown value for enum
还没有人认领这个 Issue。
评估
调研方向
从 betterproto/init.py 中的 _from_dict_init 开始,并按照 traceback 中所示,跟踪其对 betterproto/enum.py: from_string 的调用。使用提供的 protobuf 和 JSON 重现重复 enum 的情况,然后验证数值 enum 值能够从 from_json 成功解析,同时不会破坏字符串处理。
由索引模型根据 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 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
danielgtaylor/python-betterproto 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 5/5 一周以上 新手友好度 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 小时 新手友好度 77/100
khuisman/mcp-gee-sweet#1166 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
lugassawan/swe-workbench#823 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
gramaziokohler/compas_timber#870 ·
-
security-scan-failure
难度 2/5 1-3 小时 新手友好度 78/100
semantica-agi/semantica#2089 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 82/100
autowarefoundation/autoware_carla_scenario#500 ·
维护者通常 1 天内回复