Skip to content

chore: librarian onboard pull request: 20260407T145439Z#16574

Open
daniel-sanche wants to merge 1 commit intomainfrom
librarian-20260407T145439Z
Open

chore: librarian onboard pull request: 20260407T145439Z#16574
daniel-sanche wants to merge 1 commit intomainfrom
librarian-20260407T145439Z

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

PR created by the Librarian CLI to onboard a new Cloud Client Library.

BEGIN_COMMIT

feat: onboard a new library

PiperOrigin-RevId: 895558469
Library-IDs: google-cloud-appoptimize

END_COMMIT

Librarian Version: v0.8.3
Language Image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:234b9d1f2ddb057ed7ac6a38db0bf8163d839c65c6cf88ade52530cddebce59e

@daniel-sanche daniel-sanche requested review from a team as code owners April 7, 2026 21:56
@snippet-bot
Copy link
Copy Markdown

snippet-bot bot commented Apr 7, 2026

Here is the summary of changes.

You are about to add 10 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the google-cloud-appoptimize library, a new Python client for the App Optimize API (v1beta). The changes encompass the full suite of generated client code, including sync and async interfaces, gRPC and REST transports, and associated samples and tests. Feedback highlights critical bugs in the REST transport's debug logging and example interceptor code. Suggestions for improvement include optimizing query parameter processing using MessageToDict and ensuring deterministic output by programmatically sorting dictionary keys in path parsing and query parameter generation.

): # pragma: NO COVER
try:
response_payload = app_optimize.Report.to_json(response)
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logging code incorrectly attempts to call to_json on the requests.Response object (response) instead of the parsed proto message (resp). This will cause an error during logging when DEBUG level is enabled.

Suggested change
except:
response_payload = app_optimize.Report.to_json(resp)

Comment on lines +1164 to +1166
response
)
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logging code incorrectly attempts to call to_json on the requests.Response object (response) instead of the parsed proto message (resp). This will cause an error during logging when DEBUG level is enabled.

                    response_payload = app_optimize.ListReportsResponse.to_json(
                        resp
                    )

): # pragma: NO COVER
try:
response_payload = app_optimize.ReadReportResponse.to_json(response)
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The logging code incorrectly attempts to call to_json on the requests.Response object (response) instead of the parsed proto message (resp). This will cause an error during logging when DEBUG level is enabled.

Suggested change
except:
response_payload = app_optimize.ReadReportResponse.to_json(resp)

Comment on lines +138 to +143
json_format.MessageToJson(
transcoded_request["query_params"],
use_integers_for_enums=True,
)
)
query_params.update(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using json_format.MessageToDict is more efficient than serializing to a JSON string and then parsing it back into a dictionary. This improvement can be applied to all similar occurrences in this file.

Suggested change
json_format.MessageToJson(
transcoded_request["query_params"],
use_integers_for_enums=True,
)
)
query_params.update(
query_params = json_format.MessageToDict(
transcoded_request["query_params"],
use_integers_for_enums=True,
)


query_params["$alt"] = "json;enum-encoding=int"
return query_params

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it instead of relying on manual ordering in the code. This ensures deterministic behavior for the generated query parameters. This improvement can be applied to all _get_query_params_json methods in this file.

Suggested change
return dict(sorted(query_params.items()))
References
  1. To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it (e.g., using dict(sorted(metadata.items()))) instead of relying on manual ordering in the code.

class MyCustomAppOptimizeInterceptor(AppOptimizeRestInterceptor):
def pre_create_report(self, request, metadata):
logging.log(f"Received request: {request}")
return request, metadata
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The example interceptor uses logging.log without specifying a log level, which will raise a TypeError. It should use a specific level method like logging.info or provide the level as the first argument. This applies to all logging calls in the example.

Suggested change
return request, metadata
logging.info(f"Received request: {request}")

path,
)
return m.groupdict() if m else {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it instead of relying on manual ordering in the code. This applies to all path parsing methods in this class.

Suggested change
return dict(sorted(m.groupdict().items())) if m else {}
References
  1. To ensure dictionary keys remain sorted without manual effort, programmatically sort the dictionary before returning it (e.g., using dict(sorted(metadata.items()))) instead of relying on manual ordering in the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant