fix(openapi): preserve falsy query parameter values#6286
Open
VectorPeak wants to merge 4 commits into
Open
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem / Solution:
What Problem This Solves
RestApiTool._prepare_request_params()previously used a truthiness check when collecting OpenAPI query parameters:That treated "absent" and "provided but falsy" as the same thing. In Python, values such as
False,0,"", andNoneall fail a truthiness check, but they do not carry the same meaning when constructing query parameters.For generated REST tools,
Falseand0can be intentional caller-provided values. Common examples include boolean filters and pagination-style parameters such as:Before this change, those values were removed from
request_params["params"]before request execution. That means APIs which distinguish omitted parameters from explicitfalseor0could apply defaults or different filtering/pagination behavior than the caller requested.Changes
The query-parameter filter now excludes only values that represent absence under the existing behavior:
This preserves explicit falsy-but-valid query values such as
Falseand0, while keeping the previous empty-string omission behavior unchanged.This PR also includes a one-line local test stability fix in
cli_deploy._validate_agent_import()that invalidates importlib caches before importing newly staged temporary agent packages. That was needed to make the repository full unit suite pass consistently in a clean Linux filesystem clone.\n\nThe OpenAPI query-parameter change is intentionally narrow:\n\n- only OpenAPI parameters withparam_location == "query"are affectedEvidence
The regression test added in this PR exercises
RestApiTool._prepare_request_params()directly and verifies the request-parameter dictionary before request execution:include_inactive=Falseis preserved inrequest_params["params"]page=0is preserved inrequest_params["params"]empty_param=""remains omitted fromrequest_params["params"]Together with the nearby existing query-parameter test, this keeps the prior empty-string omission behavior covered while adding explicit coverage for falsy-but-valid values.
Targeted local validation passed:
Result:
Broader focused validation for the same test file also passed:
Result:
Possible call chain / impact
An OpenAPI operation is parsed into
ApiParameterentries, then a generatedRestApiToolreceives tool-call kwargs. During execution:Before this change, explicit query kwargs like:
{"include_inactive": False, "page": 0}were filtered out before reaching the params dict. After this change, those values remain in
request_params["params"], so the generated tool passes the caller-selected falsy values to the samehttpx.AsyncClient.request(..., params=...)path used for other query parameters.This PR does not claim new wire-level serialization behavior; it only changes which explicit query values are admitted into the existing params path.
Testing Plan
Unit Tests:
Passed locally:
uv run --with pytest --with pytest-asyncio --with pytest-mock pytest tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py -q48 passed, 21 warningsuv run --python 3.12 --extra test pytest tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRestApiTool::test_prepare_request_params_no_credential tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.py::TestRestApiTool::test_prepare_request_params_preserves_falsy_query_parameter_values -p no:cacheprovider -q2 passed, 4 warningsFull unit suite validation:
uv run --python 3.12 --extra test --with pytest --with pytest-asyncio --with pytest-mock --with pytest-xdist pytest tests/unittests -q --tb=short7964 passed, 19 skipped, 31 xfailed, 9 xpassed, 1803 warnings, 6 subtests passedimportlib.invalidate_caches()for_validate_agent_import()test stability.Additional checks:
uv run --with ruff==0.15.17 ruff check src/google/adk/tools/openapi_tool/openapi_spec_parser/rest_api_tool.py tests/unittests/tools/openapi_tool/openapi_spec_parser/test_rest_api_tool.pyAll checks passed!git diff --checkManual End-to-End (E2E) Tests:
Performed a local manual smoke test that exercises the changed request path through
RestApiTool.call()with an injected HTTP client. The smoke verified that:include_inactive=Falseandpage=0are preserved in the outgoingparamspassed toclient.request(...)empty_param=""is still omitted from outgoing query params_validate_agent_import()can validate consecutive newly-created temporary agent packages after refreshing importlib cachesCommand:
Result:
Checklist
Additional context
Before this change,
Falseand0were both excluded fromrequest_params["params"]. The new regression test verifies that:include_inactive=Falseis preservedpage=0is preservedempty_param=""is still omitted