Double underscore breaks existing code in betterproto v2/master
还没有人认领这个 Issue。
评估
调研方向
首先,针对 src/test.proto 运行报告中的 grpc_tools.protoc 命令,并确认 field__json 被生成为 field_json。然后,追踪生成过程中涉及的 betterproto v2 Python 字段名称处理。完成的标准是生成的 dataclass 保留 field__json,并且其字典/JSON 表示与原始 proto 字段名保持一致。
由索引模型根据 Issue 内容生成。
描述
Summary
Double underscore breaks existing code
Reproduction Steps
When we try compiling the following proto-file, the field field__json becomes field_json
syntax = "proto3";
package test;
message TestMessage {
string field__json = 1;
}
@dataclass(eq=False, repr=False, config={"extra": "forbid"})
class TestMessage(betterproto.Message):
field__json: str = betterproto.string_field(1)
python -m grpc_tools.protoc --python_betterproto_opt=pydantic_dataclasses --python_betterproto_out=src -Isrc src/test.proto
Expected Results
If we build the same code with betterproto v1, or with the standard compiler (python -m grpc_tools.protoc --python_out=src --pyi_out=src src/test.proto) the field name will remain unchanged.
Not only does this break current code, but this will also impact how a dict/JSON is being generated based on the data class/structure.
I would imagine this behaviour as unwanted and if we want to sanitize filed name, I think it would be better to do in the original proto-file (e.g. using tools like buf).
Actual Results
above
System Information
protoc --version; python --version; poetry run pip show betterproto
libprotoc 27.3
zsh: command not found: python
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: /Users/mikhailgalanin/Library/Caches/pypoetry/virtualenvs/betterproto-repro-O0YfRvug-py3.12/lib/python3.12/site-packages
Requires: grpclib, python-dateutil, typing-extensions
Required-by: betterproto-repro
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
-
[Resource]: Lore未关闭resource-submission validation-passed
难度 1/5 1 小时以内 新手友好度 88/100
hesreallyhim/awesome-claude-code#3234 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openminion/openminion#376 ·
维护者通常 1 天内回复
-
Type: ☹︎ Bug
难度 2/5 1-3 小时 新手友好度 78/100
posit-dev/great-tables#1028 ·
维护者通常 1 天内回复
-
integration: apple_tv
难度 2/5 1-3 小时 新手友好度 78/100
home-assistant/core#188282 · 1 条评论 ·
维护者通常 1 天内回复
-
A "since" range is worded as a career: "the past two seasons" says "regular season career (2025 on)"未关闭P4: low
难度 2/5 1-3 小时 新手友好度 65/100
jeffknupp/association#538 ·