danielgtaylor / python-betterproto

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

Missing data in proto maps #442

Open BananaLoaf opened 2 years ago

BananaLoaf commented 2 years ago

I have a theoretical proto file message defined as:

message Measurement {
  double pressure = 1;
  double temperature = 2;
}

message MeasurementMap {
  map<string, Measurement> measurements = 1;
}

service WeatherStation {
  rpc GetClimate (Empty) returns (MeasurementMap) {}
}

The problem is that if MeasurementMap contains a Measurement with all fields equal to 0, betterproto server replies with something like this:

{
    "measurements": [
        {
            "key": "rpi1",
            "value": {
                "pressure": 1.01,
                "temperature": 25.2,
            }
        },
        {
            "key": "rpi2"
        }
    ]
}

Second key does not have any value next to it which makes Postman throw a tantrum about "null value not having pressure field"

For comparison, here is the default behaviour of grpclib, which Postman receives and parses A-OK:

{
    "measurement": [
        {
            "key": "rpi1",
            "value": {
                "pressure": 1.01,
                "temperature": 25.2
            }
        },
        {
            "key": "rpi2",
            "value": {}
        }
    ]
}
BananaLoaf commented 2 years ago

It turns out that this issue is not an issue if reflections (#443) work