Skip to content

[WIP] Experiment deterministic resource names#16569

Draft
ohmayr wants to merge 6 commits intomainfrom
experiment-deterministic-resource-names
Draft

[WIP] Experiment deterministic resource names#16569
ohmayr wants to merge 6 commits intomainfrom
experiment-deterministic-resource-names

Conversation

@ohmayr
Copy link
Copy Markdown
Contributor

@ohmayr ohmayr commented Apr 7, 2026

Experiment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces changes to ensure deterministic output in the GAPIC generator and improves resource name collision resolution by prefixing foreign domains. Key updates include modifying resource_messages to return sorted sequences, updating Jinja2 templates to use disambiguated method names, and adding a new configuration for Dialogflow. Feedback includes a critical request to revert a hardcoded local path in the requirements file, a suggestion to use standard dictionaries for sorted items, and recommendations to remove redundant properties and move inline imports to the top level.

@@ -1,5 +1,5 @@
click
gapic-generator==1.30.13 # https://github.com/googleapis/gapic-generator-python/releases/tag/v1.30.13
-e /usr/local/google/home/omairn/git/googleapis/google-cloud-python/packages/gapic-generator
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The use of a hardcoded local absolute path (-e /usr/local/google/...) will break the build for other developers and in CI/CD environments. Please revert this to a versioned dependency or a relative path if necessary for the experiment.

gapic-generator==1.30.13 # https://github.com/googleapis/gapic-generator-python/releases/tag/v1.30.13

Comment on lines 174 to 179
return collections.OrderedDict(
itertools.chain(
file_resource_messages,
resource_messages,
sorted(
itertools.chain(file_resource_messages, resource_messages),
key=lambda item: item[0]
)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In modern Python (3.7+), the standard dict preserves insertion order. Following the general rules for this repository, you should use dict(sorted(...)) instead of collections.OrderedDict to ensure determinism more concisely.

Suggested change
return collections.OrderedDict(
itertools.chain(
file_resource_messages,
resource_messages,
sorted(
itertools.chain(file_resource_messages, resource_messages),
key=lambda item: item[0]
)
)
return dict(
sorted(
itertools.chain(file_resource_messages, resource_messages),
key=lambda item: item[0]
)
)
References
  1. To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it (e.g., using dict(sorted(metadata.items()))) instead of relying on manual ordering in the code.

Comment on lines +2244 to +2252
@utils.cached_property
def deterministic_resource_messages(self) -> Sequence[MessageType]:
"""Returns a sorted sequence of resource messages to guarantee deterministic output order."""
return tuple(
sorted(
self.resource_messages,
key=lambda r: r.resource_type_full_path or r.name
)
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The deterministic_resource_messages property appears to be redundant because the resource_messages property (defined later in this file) has also been updated to return a sorted sequence. Since the templates and tests now rely on resource_messages being deterministic, this extra property can be removed.

Comment on lines +2257 to +2258
import collections
from gapic import utils
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Inline imports are generally discouraged unless they are necessary to avoid circular dependencies. collections is a standard library module that should be imported at the top level. Furthermore, utils is already available in the global scope of this module, making the local import redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant