danielgtaylor / python-betterproto

Clean, modern, Python 3.6+ code generator & library for Protobuf 3 and async gRPC
MIT License
1.5k stars 209 forks source link

ALL_CAPS message fields are parsed incorrectly. #11

Closed acetylen closed 4 years ago

acetylen commented 4 years ago
$ cat filedata.proto
syntax = "proto3";
package filedata;

message FileData {
  uint32 FRAGMENT_NR = 1;
  bytes DATA = 2;
  uint64 UID = 3;
}

$ protoc --python_betterproto_out . filedata.proto
Writing __init__.py
Writing filedata.py
$ cat filedata.py
# Generated by the protocol buffer compiler.  DO NOT EDIT!
# sources: filedata.proto
# plugin: python-betterproto
from dataclasses import dataclass

import betterproto

@dataclass
class FileData(betterproto.Message):
    f_r_a_g_m_e_n_t__n_r: int = betterproto.uint32_field(1)
    d_a_t_a: bytes = betterproto.bytes_field(2)
    u_i_d: int = betterproto.uint64_field(3)

I assume this has something to do with the parser thinking they are enums?

Rewriting our schema is unfortunately not an option, it's made to be backwards-compatible and encompasses thousands of fields over several hundred message types.

danielgtaylor commented 4 years ago

I suspect the case conversion code is broken. Nice catch!