danielgtaylor / danielgtaylor/python-betterproto
Double underscore breaks existing code in betterproto v2/master
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
### 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: danielgtaylor@gmail.com
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
- [X] I have searched the issues for duplicates.
- [X] I have shown the entire traceback, if possible.
- [X] I have verified this issue occurs on the latest prelease of betterproto which can be installed using `pip install -U --pre betterproto`, if possible.
Beitragsleitfaden
Rechercherichtung
Führe zunächst den gemeldeten grpc_tools.protoc-Befehl gegen src/test.proto aus und bestätige, dass field__json als field_json generiert wird. Verfolge anschließend die an der Generierung beteiligte Python-Feldnamensbehandlung von betterproto v2. Die Aufgabe ist abgeschlossen, wenn die generierte Dataclass field__json beibehält und ihre Dictionary-/JSON-Darstellung mit dem ursprünglichen Proto-Feldnamen konsistent bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100