GeezerVison is showing github.com — fix: correct import for request message type by dizcology · Pull Request #1273 · googleapis/gapic-generator-python
This repository was archived by the owner on Aug 25, 2026. It is now read-only.
Conversation
dizcology
commented
Apr 11, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes: #1263
The generated snippet where the request message type is external to the client library package now becomes:
from google.cloud import resourcemanager_v3
from google.iam.v1 import iam_policy_pb2 # type: ignore
def sample_get_iam_policy():
# Create a client
client = resourcemanager_v3.ProjectsClient()
# Initialize request argument(s)
request = iam_policy_pb2.GetIamPolicyRequest(
resource="resource_value",
)
# Make the request
response = client.get_iam_policy(request=request)
# Handle the response
print(response)
Additional changes:
- pytest fixtures in tests/unit/samplegen/test_samplegen.py are refactored to make it easier to add new unit test code without duplicating much of the code.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks for fixing this! The changes look good. I noticed a formatting issue in the downstream repo where 2 import statements appear are on the same line. Please could you take a look?
+ from google.cloud import resourcemanager_v3from google.iam.v1 import iam_policy_pb2 # type: ignore
Steps to re-create the issue:
- Modify the WORKSPACE file here to use
local_repository instead of http_archive and point to a clone of gapic generator python with this branch.
- Run
bazel build //google/cloud/resourcemanager/v3:resourcemanager-v3-py in the root of googleapis where you modified the WORKSPACE file in step 1
- Run the following in a clone of https://github.com/googleapis/python-resource-manager
docker run --rm --user $(id -u):$(id -g) -v $(pwd):/repo -v $HOME/git/googleapis/bazel-bin:/bazel-bin gcr.io/cloud-devrel-public-resources/owlbot-cli:latest copy-bazel-bin --source-dir /bazel-bin --dest /repo
docker run --user $(id -u):$(id -g) --rm -v $(pwd):/repo -w /repo gcr.io/cloud-devrel-public-resources/owlbot-python:latest
- Check the diff
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
parthea
commented
Apr 11, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
@dizcology I only see the formatting issue with the imports when I apply the changes from this PR. I don't see the issue in the main branch. It could be that the changes in this PR exposed an underlying issue. I haven't debugged that part of the code yet. Would you be interested in adding a test to verify the output of the sample generator? I don't see changes to the golden files based on the changes in this PR so it's possible that we don't have any checks for the generated sample code.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dizcology
commented
Apr 12, 2022
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
Looks like there is some magic in client method docstring rendering that suppresses multiple new lines in some cases, so that strip call was not needed after all. Updated generated code:
def get_iam_policy(self,
...
) -> policy_pb2.Policy:
r"""Returns the IAM access control policy for the
specified project. Permission is denied if the policy or
the resource do not exist.
.. code-block:: python
from google.cloud import resourcemanager_v3
from google.iam.v1 import iam_policy_pb2 # type: ignore
def sample_get_iam_policy():
# Create a client
client = resourcemanager_v3.ProjectsClient()
# Initialize request argument(s)
request = iam_policy_pb2.GetIamPolicyRequest(
resource="resource_value",
)
# Make the request
response = client.get_iam_policy(request=request)
# Handle the response
print(response)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
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.
Milestone
No milestone
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.
|