-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
protoc should not populate json_name
in descriptor if no json_name
was specified
#5587
Comments
The one thing this issue fails to address is how this works in a language neutral way. If two language runtimes fail to make the same default json field name because of a quirk with one runtime then they can't work together. Sure that might be a bug with the quirked runtime, but the whole issue could just be avoided if the runtime was given the same json name as the other runtimes via protoc. On top of that, calculating a json name takes time. It may not be a long time, but it is time and memory. It's not time and memory to calculate it ahead of time and reference it as a constant value (depending on the runtime). The last point doesn't seem like much of an issue. You should be distributing |
The biggest complaint is that it makes it impossible to tell whether a user specified a We have a lot of code still on protobuf 3.0.0, and when we try to upgrade to a newer protobuf release, all the json field names change. We can use the As far as the time burden of calculating json names… in compiled runtimes that often happens at generation time (it does in Go, currently), and even in interpreted languages, it's surely highly cacheable. Besides, they all have to have the code/machinery to be able to handle descriptors that lack It's true that recreating a |
https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/command_line_interface.cc#L1972 |
Yeah, I think a commandline option is perfect. It should always reflect the |
Any updates on this? Would sending a PR help? |
Sorry this slipped off my radar. Usually we try to avoid new options but maybe it is justified in this case. I'm guessing if we just removed |
I don't think we should change the current behavior as users are already relying on it. I am also not a fan of adding more command line option, as this doesn't seem like a common feature that other people are asking for, and I really don't like to add more switch for one use-case. Can this problem be solved at the application level rather than at the protobuf level? Does it really matter if the json_name was explicitly specified or not? If you make the lowerCamelCase transformation on the field name and that matches the json_name option, can you assume that the json_name is not specified? Even if the json_name is explicitly specified in that case, does it matter? |
I thought I described why earlier, but no, it is not solvable at an application level, because the way protoc currently populates A commandline flag would be perfect. |
btw, if y'all don't add a commandline option, we will be forced to fork protoc internally, and add one 😞 Either that or specify a |
Fair enough. If you can put together a PR for this command line option, it may help. Point taken that this can reduce the size bloat on the serialized descriptor, and most languages should already handle the fallback in case |
I think removing Another option would be to add a field to |
Yea, I think having something like |
On second thought, I think it has to be the negative for backwards compatibility reasons, unless I'm confusing myself, ie The work as I see it:
Note that for backwards compatibility, when running a plugin (both the builtins and external plugins), you need to do the following with this (in pseudo-code):
|
Remember that optional bool json_name_configured = 11 [default=true]; |
Good point. One issue though is that makes the definition a tad weird - even if no FileDescriptorSet provider (ie protoc et al) would produce this, what does it mean when json_name == “” && json_name_configured == true? |
string foo = 1 [json_name=""]; :P (Related: #5682) |
Lol |
I'm fine with |
I think it needs to be json_name_not_explicitly_set, this does matter for being able to really reason about the value of the field, see above |
@elharo Do you know if someone is still working on this? Can we expect this config to be part of future releases? I am willing to contribute if this is not being worked on. |
I don't think anyone is working on this. However, reading through this now I confess I don't see a use case for this feature. That is, why does this matter? Until I can achieve clarity on that I don't think I'd be likely to approve any such PR. Perhaps someone else sees something here I don't. My thinking (not dispositive) is as follows:
I'm not sure about the "fully" in step 1. There are command line options that change this, but that doesn't change my conclusion. This feature simply doesn't seem to be needed, likely encourages bad code and non-interoperable protos, and is unlikely to be worth the added complexity in code. Metaphorically it's like trying to change the byte code emitted by javac so that we can tell whether it was indented with spaces or tabs. |
@elharo, I think the fact that an artifact of this is that |
We have built parsers that can read a file descriptor set and re-create the original The Protobuf code base also acknowledges it as a bug and a work around was introduced to deal with it. Since this change will be non-backward compatible, I recommend that we add the boolean flag Reference |
@blacktooth "Since the file descriptor set generation is different for the same .proto schema, it results in different schemas getting generated." What exactly do you mean by different here? Are some fields present in one and not the other? Are the fields renumbered? Are the fields reordered? Is the white space changed? Are comments added or removed? I don't expect the results would be byte-per-byte identical, and some of these changes are more serious than others. |
For future reference, relevant code seems to be in protobuf/compiler/command_line_interface.cc void CommandLineInterface::GetTransitiveDependencies |
Any progress on this? |
I don't think anyone is working on this right now |
Sad. #6175 was closed as a dup of this one, but summarizes the problem pretty well:
|
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
/keepopen |
Coming back to this after a long time. Reading the comments here and on related issues, it seems there is a loose consensus among external tools that if the What if we simply codified that? Here's my proposal: If a field in the This would allow existing tooling to be mostly unchanged, and would provide a solution in the rare cases when the heuristic adopted by external tooling goes wrong: re-generate your proto descriptor with a more recent version of |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
/keepopen - mind above proposal |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
/keepopen - mind above proposal |
What version of protobuf and what language are you using?
Version: v3.6.0
Language: any
What operating system (Linux, Windows, ...) and version?
n/a
What runtime / compiler are you using (e.g., python version or gcc version)
n/a
What did you do?
Steps to reproduce the behavior:
test.proto:
Command:
protoc -o /dev/stdout test.proto | protoc --decode=google.protobuf.FileDescriptorSet descriptor.proto
Output:
What did you expect to see
It should be possible to tell whether
json_name
was specified in the.proto
file. In particular, there should be a way to distinguish thatjson_name
was specified forbirth_year
, and not specified forhas_hooves
.What did you see instead?
It is impossible to tell whether
json_name
was specified in the.proto
file, becauseprotoc
invents ajson_name
for each field, regardless.Anything else
jsonpb
, there is anOrigName
option. But it's all-or-nothing. If you opt out of the java-ish names, you also opt out of being able to override a name..proto
file from the descriptor.The text was updated successfully, but these errors were encountered: