GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(snippetgen): fix client streaming samples by busunkim96 · Pull Request #1061 · googleapis/gapic-generator-python

This repository was archived by the owner on Aug 25, 2026. It is now read-only.

Conversation

@busunkim96

@busunkim96 busunkim96 commented Nov 2, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #1014 and unblocks #1043.

NOTE: Some real world APIs expect the first request to pass a config (example) so the generated samples will not work out of the box. This will be addressed when the new sample config language is sorted out.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
busunkim96 added 2 commits November 1, 2021 23:48
@busunkim96
fix(snippetgen) fix streaming samples
8d602bb
@busunkim96
test: fix tests
b6c56aa
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 2, 2021
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 2, 2021
busunkim96
busunkim96 commented Nov 2, 2021
View reviewed changes
Comment thread gapic/samplegen/samplegen.py
Comment on lines -554 to -560
client_streaming_forms = {
types.CallingForm.RequestStreamingClient,
types.CallingForm.RequestStreamingBidi,
}

if len(base_param_to_attrs) > 1 and calling_form in client_streaming_forms:
raise types.InvalidRequestSetup(
"Too many base parameters for client side streaming form"
)

@busunkim96 busunkim96 Nov 2, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@software-dov 👋 I'm having trouble understanding this error, would you remember what this was written to prevent?

Some streaming method request messages have 2+ required fields (pubsub), so the current snippetgen logic adds two fields to the dictionary. That causes this error to be raised. Are fields expected to be set differently for streaming?

# Request passed to `validate_and_transform_request`
[
   {
      "field":"subscription",
      "value":"projects/{project}/subscriptions/{subscription}"
   },
   {
      "field":"stream_ack_deadline_seconds",
      "value":2813
   }
]

I see two unit tests that raise this error, but I don't see any pre-existing tests showing a valid sample config for a client streaming method.

gapic-generator-python/tests/unit/samplegen/test_samplegen.py

Lines 1353 to 1402 in a8d2b3a

def test_single_request_client_streaming(dummy_api_schema,
calling_form=types.CallingForm.RequestStreamingClient):
# Each API client method really only takes one parameter:
# either a single protobuf message or an iterable of protobuf messages.
# With unary request methods, python lets us describe attributes as positional
# and keyword parameters, which simplifies request construction.
# The 'base' in the transformed request refers to an attribute, and the
# 'field's refer to sub-attributes.
# Client streaming and bidirectional streaming methods can't use this notation,
# and generate an exception if there is more than one 'base'.
input_type = DummyMessage(
fields={
"cephalopod": DummyField(
message=DummyMessage(
fields={
"order": DummyField(
message=DummyMessage(type="ORDER_TYPE")
)
},
type="CEPHALOPOD_TYPE"
)
),
"gastropod": DummyField(
message=DummyMessage(
fields={
"order": DummyField(
message=DummyMessage(type="ORDER_TYPE")
)
},
type="GASTROPOD_TYPE"
)
)
},
type="MOLLUSC_TYPE"
)
v = samplegen.Validator(DummyMethod(input=input_type), dummy_api_schema)
with pytest.raises(types.InvalidRequestSetup):
v.validate_and_transform_request(
types.CallingForm.RequestStreamingClient,
[
{"field": "cephalopod.order", "value": "cephalopoda"},
{"field": "gastropod.order", "value": "pulmonata"},
],
)
def test_single_request_bidi_streaming():
test_single_request_client_streaming(
types.CallingForm.RequestStreamingBidi)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@software-dov software-dov Nov 5, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I really don't remember what was going on here. My guess is that I was mildly incorrect about the actual python method signature convention and I was trying to imply that we only wanted a single request to be put into a list...?

TL;DR: It's probably a bug or at least a misreading of the spec on my part.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

busunkim96 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
busunkim96 and others added 3 commits November 5, 2021 20:38
@busunkim96
test: delete obsolete tests, ignore snippetgen goldens for autopep8
06407c7
@busunkim96
chore: update .github
80d33cb
@busunkim96
Merge branch 'master' into fix-streaming-samples
4c6adb4
@busunkim96
busunkim96 marked this pull request as ready for review November 5, 2021 21:17
@busunkim96
busunkim96 requested review from a team November 5, 2021 21:17
@busunkim96

busunkim96 commented Nov 5, 2021

Copy link
Copy Markdown
Contributor Author

This is ready for review, PTAL @software-dov @parthea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

busunkim96
busunkim96 commented Nov 5, 2021
View reviewed changes
Comment thread .../generated_samples/logging_generated_logging_v2_logging_service_v2_tail_log_entries_async.py
# 'logging_v2.TailLogEntriesRequest' objects
# Here we create a generator that yields a single `request` for
# demonstrative purposes.
requests = [request]

@busunkim96 busunkim96 Nov 5, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

One simpler alternative is:

requests = iter([requests])

I chose the generator over iter() to nudge folks towards generating requests on demand.

Opinions/suggestions on the best way to present client streaming welcome!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@busunkim96
Merge branch 'master' into fix-streaming-samples
4dc4db9
parthea
parthea approved these changes Nov 6, 2021
View reviewed changes
@tseaver
Merge branch 'master' into fix-streaming-samples
4c7710b
@busunkim96
busunkim96 merged commit 64b9ad6 into master Nov 8, 2021
@busunkim96
busunkim96 deleted the fix-streaming-samples branch November 8, 2021 17:57
This was referenced Jan 18, 2022
chore(master): release reverted #1133
Merged
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@software-dov software-dov software-dov left review comments
@parthea parthea parthea approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement. samples Issues that are directly related to samples.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

snippetgen: streaming methods have syntax errors

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@busunkim96 @software-dov @parthea @tseaver
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.