New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect field presence with null JSON values #751
Comments
Using nullable types for
I'm not sure what you mean by this, hazzer for the void main() {
final p = Property();
print(p.hasPrice()); // prints false
print(p.hasField(3)); // prints false
p.price = 0;
print(p.hasPrice()); // prints true
print(p.hasField(3)); // prints true
} Why do you say it always returns true? |
I'm using an SQL database and have to merge data to a proto object in order to send back a response using gRPC. I didn't think it was caused by I believe the issue is that if the database returns a field null, it is replaced by the default value during the merge. final pl = Property();
print(pl.toProto3Json()); // {}
print('price: ${pl.price}'); // price: 0
print('has price: ${pl.hasPrice()}'); // has price: false
pl.mergeFromProto3Json({'id': 10, 'price': null});
print(pl.toProto3Json()); // {id: 10, price: 0}
print('price: ${pl.price}'); // price: 0
print('has price: ${pl.hasPrice()}'); // has price: true |
Is there any reason to not use native dart null safety? The |
This is the bug.
The problem is it is too expensive for us to migrate users of this library after such an invasive change. Google stores most of its source code in a mono repo, and third-party dependencies (such as protobuf.dart) only have one version in the repo. So if we do a backwards incompatible change in protobuf.dart, we have to update all affected users in Google before merging it. For an invasive change like changing return type of a getter it will probably require refactoring a few hundred thousands line of code. We can't just bump the major version number and expect users in Google to update their protobuf dependency gradually. This is also one of the main blockers for a lot of other bug fixes and improvements in this library. |
null
is accepted as a int32
value in proto3 JSON decoder
@sigurdm points out this part in proto3 JSON spec:
So it's correct to accept I'm not sure what the presence check for the field should return though. I think it should return 'true' as the field is present in the message. Since the spec doesn't have proto3 optional fields yet it doesn't say what the presence checks should return when value of a field is |
I talked to the protobuf team about this. There is no spec that covers this case, but when we see |
null
is accepted as a int32
value in proto3 JSON decoder
Wouldn't it be possible to make if available via an experimental kind of attribute. Because now it's very dangerous to use the generated code in my opinion. |
This bug should be fixed with #763. |
When I create dart files using
protoc
, I get theprice
field as follow;Which is fine, If I need to check if the price is null I can use
hasPrice()
to see it's null. Well, that always returnstrue
.When we looked at the implentation of
has
method infield_set.dart
, it makes sense to return alwaystrue
protobuf.dart/protobuf/lib/src/protobuf/field_set.dart
Lines 468 to 473 in cd0ff30
Since the
price
has a default value of0
, I can't null check it.The text was updated successfully, but these errors were encountered: