Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Order of entries in generated 'enums' is not stable #2319

Closed
tseaver opened this issue Sep 19, 2018 · 19 comments · Fixed by #2453
Closed

Order of entries in generated 'enums' is not stable #2319

tseaver opened this issue Sep 19, 2018 · 19 comments · Fixed by #2453
Assignees
Labels
lang: python Issues specific to Python. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. yoshi

Comments

@tseaver
Copy link
Contributor

tseaver commented Sep 19, 2018

E.g., see: https://github.com/GoogleCloudPlatform/google-cloud-python/pull/6015/files.

The order should match the order in the .proto file, except that they might be collected from more than one: if that case in general, then sort them.

@tseaver tseaver added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. lang: python Issues specific to Python. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Sep 19, 2018
@tseaver
Copy link
Contributor Author

tseaver commented Sep 26, 2018

@tseaver tseaver added yoshi priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 11, 2018
@tseaver
Copy link
Contributor Author

tseaver commented Oct 15, 2018

@JustinBeckwith, @theacodes per today's call.

@theacodes
Copy link

@lukesneeringer @andreamlin any more information we can provide here?

@tseaver
Copy link
Contributor Author

tseaver commented Oct 29, 2018

Any update here?

@lukesneeringer
Copy link
Contributor

Hey folks, one question: Is the order non-deterministic or did the order remain deterministic and change?

I think this change may have been caused by some work done to sort other components (not specific to Python).

@andreamlin
Copy link
Contributor

Thanks for reporting this.

Forewarning: I'm not a Python expert.

  1. for PR https://github.com/GoogleCloudPlatform/google-cloud-python/pull/6015/files, I can't see what the change is, besides that the order of class defs is swapped. Does this matter, given that the classes don't reference each other?

  2. For the requirement that "The order should match the order in the .proto file, except that they might be collected from more than one: if that case in general, then sort them.":
    Assuming the class order does matter, wouldn't it be a breaking change to introduce a new protofile when there was only one protofile before? The order would get rearranged because now they're being sorted.

@andreamlin
Copy link
Contributor

Talked to Luke offline.

  1. Confirming that the PRs are annoying changes, but this isn't a semantic change?

@andreamlin
Copy link
Contributor

andreamlin commented Oct 29, 2018

@vam-google Would https://github.com/googleapis/googleapis/blame/master/google/bigtable/admin/v2/BUILD.bazel have to do with this? Since that explicitly lists out the order in which the proto files are given to gapic-generator.

If so, I think we can close this issue; the new Bazel build files will deterministically order the proto files. This could result in more no-op library refreshes down the road as they're being rolled out.

@lukesneeringer
Copy link
Contributor

Would it be possible to update this specific Bazel build file to match what was in the legacy configuration (which would theoretically revert the enum sort order in Bigtable)?

@andreamlin andreamlin assigned andreamlin and unassigned vam-google Oct 29, 2018
@andreamlin
Copy link
Contributor

Talked to @vam-google and it can't be related because that BUILD file was pushed after this issue was filed.

I've been looking at how we generate the enum classes, and it seems to come from the order the proto files are passed in. This seems like a deterministic order. However, as Luke mentioned, we have been going through some refactorings that change the the order of surface entities in the clients. This churn should settle down in a while.

@tseaver
Copy link
Contributor Author

tseaver commented Oct 30, 2018

This is not a case of one-time changes: I've seen multiple autosynth-driven PRs which do nothing more than change enum order: approving one doesn't make the problem go away. When I run synthtool on my machine, I have gotten a different order than the one in the autosynth PR.

Note that I don't really care about any specific order, only that it be stable over time.

@tseaver tseaver reopened this Nov 12, 2018
@tseaver
Copy link
Contributor Author

tseaver commented Nov 12, 2018

@andreamlin I don't know how to tell if the change from #2418 has actually been rolled out to the artman image: is there some way to check locally using synthtool?

@tseaver
Copy link
Contributor Author

tseaver commented Nov 21, 2018

I believe this issue is now closed, although, like Ahrnuld, "I'll be back!" if it pops up again in future autosynth runs.

@tseaver tseaver closed this as completed Nov 21, 2018
@tseaver
Copy link
Contributor Author

tseaver commented Nov 22, 2018

Sigh.

@tseaver tseaver reopened this Nov 22, 2018
@tseaver
Copy link
Contributor Author

tseaver commented Nov 28, 2018

@andreamlin Is there a way we could just sort the top-level enums / messages by name, and sort the enums within messages by name? I can't see a way to get that done, looking at transformer/py/PythonGapicSurfaceTransformer.java or transformer/GrpcElementDocTransformer.java.

@andreamlin
Copy link
Contributor

@tseaver Sure, if we're fine with a one-time change to the surface that orders all existing enums. I can give it a shot

@andreamlin
Copy link
Contributor

@tseaver See #2453 for a fix and googleapis/google-cloud-python#6707 for an example of what happens after that PR is applied.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang: python Issues specific to Python. priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. yoshi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants