-
Notifications
You must be signed in to change notification settings - Fork 90
Modified reserved word field names included in field masks. #227
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
Comments
Related bug in the Ads client library: googleads/google-ads-python#454 |
Turning class BadMessage(proto.Message):
class = proto.Field(proto.STRING, number=1) The Possible solutions:
class BetterMessage(proto.Message):
# strawman name
type_ = proto.Field(proto.STRING, number=1, disambiguated_name="type")
bm = BetterMessage()
bm.type_ = "has type"
fm = protobuf_helpers.field_mask(None, bm._pb)
assert fm.paths[0] == "type" Pros:
Cons:
Pros:
Cons:
What do you think? |
Option |
I'm not 100% sure that option 1 is feasible. I'd want a day or so to run experiments indicating that the proposed change works the way I want it to, then some time to run a formal design through other people. Given those two things, I anticipate implementation to be trivial. |
Sounds good - can you let me know how the design/review process goes so that we can decide whether we need a temporary workaround in the library? |
My guess is that It looks like this is the reason we're able to have different proto-plus and vanilla proto names? I cannot actually find a docstring for https://googleapis.dev/python/protobuf/latest/google/protobuf/json_format.html import json
import proto
class HasType(proto.Message):
type_ = proto.Field(proto.STRING, number=1,)
ht = HasType(type_="has type")
print(HasType.to_json(ht, preserving_proto_field_name=False)) # {"type": "has type"}
print(HasType.to_json(ht, preserving_proto_field_name=True)) # {"type_": "has type"} Are there rules around proto field naming that we could take advantage of to more safely pursue option 2? |
Recapping discussion in email thread: @lukesneeringer pointed out that we can safely strip away trailing The easiest solution is to modify the field mask logic in |
I'm not sure whether this is an issue with this library, the
generator
or thefield mask helper
, but it seems to be incorrect behavior that's blocking for Ads users, unless there's a workaround or other solution I'm not aware of:Environment details
Python
gLinux
3.7.0
1.18.1
Steps to reproduce
Assuming we have a protobuf definition like the following:
We'll have a generated Python class similar to:
Where
type
has been modified totype_
.Normally setting
type_
isn't a problem, the issue is that this modified field name gets leaked into field masks, which are revoked by the API because it doesn't match the protobuf definition. This prevents users from executing update requests where thetype
field on any object has been modified.Here's a short script to reproduce:
The text was updated successfully, but these errors were encountered: