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

feat: add grpc transcoding, clean up unimplemented rest method/test generation #776

Closed
wants to merge 12 commits into from

Conversation

yon-mg
Copy link
Contributor

@yon-mg yon-mg commented Feb 13, 2021

This pr introduces usage of grpc transcoding and is reliant on changes made to to,
googleapis/python-api-core#146.

With this implementation of grpc transcoding, there are a few more changes that need to be made to ensure Showcase tests can run correctly. LRO rpcs, streaming rpcs and rpcs without google.api.http annotations need to also be handled. In this pr they are not implemented fully and instead rather raise errors if used in a generated client. The intention is to implement them at a later time and remove them as temporary blockers to push the grpc transcoding changes.

@yon-mg yon-mg requested a review from a team as a code owner February 13, 2021 02:33
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 13, 2021
@codecov
Copy link

codecov bot commented Feb 13, 2021

Codecov Report

Merging #776 (73b6044) into master (7c185e8) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #776   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           26        27    +1     
  Lines         1608      1642   +34     
  Branches       328       333    +5     
=========================================
+ Hits          1608      1642   +34     
Impacted Files Coverage Δ
gapic/utils/case.py 100.00% <ø> (ø)
gapic/generator/generator.py 100.00% <100.00%> (ø)
gapic/schema/wrappers.py 100.00% <100.00%> (ø)
gapic/utils/__init__.py 100.00% <100.00%> (ø)
gapic/utils/checks.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d2fe3c6...73b6044. Read the comment docs.


for http_rule in http_options:
try:
method, uri = next((method, uri) for method,uri in [
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting nit: for method, uri

Comment on lines +761 to +771
method, uri = next((method, uri) for method,uri in [
('get',http_rule.get),
('put',http_rule.put),
('post',http_rule.post),
('delete',http_rule.delete),
('patch',http_rule.patch),
('custom.path',http_rule.custom.path),
] if uri
)
except StopIteration:
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better not to catch a StopIteration and instead use explicit control flow.
This is a fairly common pattern when using next:

thing = next((generator_expression_or_iterable), None) # Or (None, None) if detupling
if not thing:
    continue # Or do some other action

Comment on lines +228 to +232
@property
def {{ method.name|snake_case }}(self) -> Callable[
[{{ method.input.ident }}],
{{ method.output.ident }}]:
return self._{{ method.name|snake_case }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the extra indirection? Is it removable?

Comment on lines +179 to +184
# Jsonify the query params
query_params = json.loads({{ method.input.ident }}.to_json(
{{ method.input.ident }}(transcoded_request['query_params']),
including_default_value_fields=False,
use_integers_for_enums=False
))
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless I'm misunderstanding something, this is turning the transcoded request back into a Request message object, turning it into a JSON string, and then turning it back into a python dict. Is that correct? Can we use to_dict instead of the indirection?
If the above is correct, can you add some comments describing the dataflow? If it's not correct, then could you describe what the dataflow is?

Copy link
Contributor

Choose a reason for hiding this comment

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

for the record: this is actually not redundant, provided we want to rely on proto+ to do the proper case conversion. to_dict doesn't do the conversion from snake_case to camelCase, only to_json does that. But the result of to_json is a string that can't be used as-is to construct the query string.

@@ -208,9 +199,38 @@ class {{ service.name }}RestTransport({{ service.name }}Transport):

# Return the response
return {{ method.output.ident }}.from_json(response.content)
{%- else %}

# Returh the response
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Return the response


<<<<<<< HEAD
Copy link
Contributor

Choose a reason for hiding this comment

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

Cruft

{%- endif %} in http_call[1] + str(body) + str(query_params.values())
{% endif %}
{% endif %}{% endfor %}
=======
Copy link
Contributor

Choose a reason for hiding this comment

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

Cruft

@@ -1144,11 +1178,13 @@ def test_{{ method.name|snake_case }}_rest_flattened():
{%- endif %} in http_call[1] + str(body)
{% endif %}
{% endif %}{% endfor %}
>>>>>>> upstream/master
Copy link
Contributor

Choose a reason for hiding this comment

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

Cruft

@parthea
Copy link
Contributor

parthea commented Aug 14, 2021

Hi @yon-mg , I'm going to close this PR due to inactivity but please feel free to re-open it.

@parthea parthea closed this Aug 14, 2021
@vam-google vam-google reopened this Sep 1, 2021
@vam-google
Copy link
Contributor

This is still needed for REGAPIC Python. Please do not close it.

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.

5 participants