-
Notifications
You must be signed in to change notification settings - Fork 1.7k
chore: sort resource messages for deterministic generation #16756
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2278,7 +2278,7 @@ def names(self) -> FrozenSet[str]: | |||||||||||||||||
| return frozenset(answer) | ||||||||||||||||||
|
|
||||||||||||||||||
| @utils.cached_property | ||||||||||||||||||
| def resource_messages(self) -> FrozenSet[MessageType]: | ||||||||||||||||||
| def resource_messages(self) -> Sequence['MessageType']: | ||||||||||||||||||
| """Returns all the resource message types used in all | ||||||||||||||||||
| request and response fields in the service.""" | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -2301,7 +2301,7 @@ def gen_indirect_resources_used(message): | |||||||||||||||||
| if resource: | ||||||||||||||||||
| yield resource | ||||||||||||||||||
|
|
||||||||||||||||||
| return frozenset( | ||||||||||||||||||
| unique_messages = frozenset( | ||||||||||||||||||
| msg | ||||||||||||||||||
| for method in self.methods.values() | ||||||||||||||||||
| for msg in chain( | ||||||||||||||||||
|
|
@@ -2316,6 +2316,15 @@ def gen_indirect_resources_used(message): | |||||||||||||||||
| ) | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Convert the set to a sorted tuple using the resource path or message name. | ||||||||||||||||||
| # This is needed to prevent non-deterministic code generation. | ||||||||||||||||||
| sorted_messages = sorted( | ||||||||||||||||||
|
ohmayr marked this conversation as resolved.
|
||||||||||||||||||
| unique_messages, | ||||||||||||||||||
| key=lambda m: m.resource_type_full_path or m.name | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+2321
to
+2324
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current sorting key m.resource_type_full_path or m.name may not guarantee deterministic ordering if multiple messages share the same resource type path or if a message name conflicts with a resource type path. Since the input is a frozenset (which is unordered), any tie in the sort key will result in non-deterministic output order across different runs. Consider using a tuple as a sort key to provide a consistent tie-breaker, such as (m.resource_type_full_path or "", m.name).
Suggested change
References
|
||||||||||||||||||
|
|
||||||||||||||||||
| return tuple(sorted_messages) | ||||||||||||||||||
|
|
||||||||||||||||||
| @utils.cached_property | ||||||||||||||||||
| def resource_messages_dict(self) -> Dict[str, MessageType]: | ||||||||||||||||||
| """Returns a dict from resource reference to | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.