Skip to content
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

fix: Adjust Field Names in URI Templates #1041

Merged
merged 2 commits into from
Oct 27, 2021

Conversation

kbandes
Copy link
Contributor

@kbandes kbandes commented Oct 26, 2021

Message fields that conflict with python reserved names are modified with a trailing underscore. If such a field appears in a uri template in an http option on a method, it needs to get the corresponding adjustment.

@kbandes kbandes requested a review from a team as a code owner October 26, 2021 21:33
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 26, 2021
@kbandes kbandes changed the title Fix:Adjust Field Names in URI Templates That Conflict with Reserved N… fix: Adjust Field Names in URI Templates That Conflict with Reserved N… Oct 26, 2021
@kbandes kbandes changed the title fix: Adjust Field Names in URI Templates That Conflict with Reserved N… fix: Adjust Field Names in URI Templates Oct 26, 2021
Copy link
Contributor

@vam-google vam-google left a comment

Choose a reason for hiding this comment

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

LGTM, with one comment

@@ -452,6 +452,19 @@ def test_method_http_options_additional_bindings():
}]


def test_method_http_options_reserved_name_in_url():
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add the short template format ({license}) here too (and ideally some other reserverd name besides license).

In general, please treat the short format as a first-class citizen for all grpc transcodding work, because this is the only format used in compute, which is the most importantlibrary relying on rest format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have that form in the unit test test_uri_conv.py. I can add other names.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the test there already includes reversed as well as license:

def test_convert_uri_fieldname():
     uri = "abc/*/license/{license}/{xyz.reversed=reversed/*}"
     expected_uri = "abc/*/license/{license_}/{xyz.reversed_=reversed/*}"
     assert utils.convert_uri_fieldnames(uri) == expected_uri

Copy link

Choose a reason for hiding this comment

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

Why is license a reserved keyword? I think this should be fixed.

@vam-google
Copy link
Contributor

Validated that these changes fix the compute problem.

@vam-google vam-google merged commit 06cd7b6 into googleapis:master Oct 27, 2021
@vam-google
Copy link
Contributor

@busunkim96, @software-dov I pushed this PR to unblock compute work. Please review it and if you have any requested chagnes, I'm happy to push them with a subsequent PR. Thanks!

@kbandes kbandes deleted the kbandes-reserved-names branch October 27, 2021 13:14
Copy link
Contributor

@busunkim96 busunkim96 left a comment

Choose a reason for hiding this comment

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

This looks good to me!

Please try to finalize this logic before any libraries using this goes GA. We've had instances in the past where changing reserved names resulted in breaking changes on GA libraries.


last = 0
pieces = []
for match in path_template._VARIABLE_RE.finditer(uri):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can _VARIABLE_RE be made public in google-api-core? Otherwise someone might assume it's only used in google-api-core and make a change that breaks the generator.

Slightly lower priority since it's in the generator code and not in generated library code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants