fix: extract URL fragment key=value pairs as query params in _prepare_request_params#4800
fix: extract URL fragment key=value pairs as query params in _prepare_request_params#4800saiprasanth-git wants to merge 5 commits intogoogle:mainfrom
Conversation
Fixes google#4598: When a URL contains a fragment component (e.g., #triggerId=abc123), the fragment was being silently dropped. This caused HTTP 400 errors when APIs expect fragment-encoded parameters to be passed as query string parameters. This change parses the URL fragment using parse_qs and merges the extracted key-value pairs into query_params (using setdefault to avoid overriding explicitly-passed values), consistent with how URL query strings are handled.
…params Adds test_prepare_request_params_extracts_fragment_key_value_pairs to verify that URL fragments containing key=value pairs (e.g. #action=POST) are correctly parsed and added to query_params, alongside query string params. Regression test for issue google#4598.
Refactor query parameter extraction to handle both query and fragment in a single loop.
Added a test using a realistic Google Cloud integration URL that has both a query string param (triggerId) and a fragment param (httpMethod). Confirms both get moved into query_params and the final URL is clean.
|
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. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where URL fragment parameters were being ignored during request preparation, causing API requests to fail. The change enhances the parameter extraction logic to correctly process key-value pairs found in both the query string and the fragment of a URL, ensuring robust handling of complex endpoint URLs and preventing data loss. This improvement makes the system more resilient to varying URL structures, particularly those generated by tools like Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @saiprasanth-git, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can visit https://cla.developers.google.com/ to see your current agreements or to sign a new one. This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in the _prepare_request_params function where URL parameters embedded in the fragment part of a URL were being silently dropped, leading to API errors. The change modifies the function to correctly parse and extract parameters from both the query string and the URL fragment, adding them to the request's query parameters. A new unit test has been added to validate this behavior, ensuring fragment parameters are processed correctly and the final URL is cleaned of both query and fragment components.
|
@googlebot I signed it |
|
@googlebot check |
|
@googlebot I signed the CLA. Please re-verify. |
|
Hi @saiprasanth-git , Thank you for your contribution! We appreciate you taking the time to submit this pull request. |
Remove unnecessary check for query and fragment in URL parsing.
|
Hi @rohityan, I've addressed the feedback:
Could you please approve the workflow runs so the remaining checks (pyink, unit tests, mypy-diff) can run? Thank you! |
Closes #4598
What's the problem?
When
_prepare_request_paramsbuilds the final request URL, it usesurlparseto split the URL into its components. The existing code was already smart enough to pull any key=value pairs out of the query string and move them intoquery_params(so httpx doesn't lose them when it sets theparamsarg). But it was completely ignoring the fragment part of the URL.This matters because
ApplicationIntegrationToolsetsometimes generates endpoint URLs like:The fragment (
httpMethod=POST) was being silently dropped, which caused the downstream API to return HTTP 400.What changed?
Instead of only looping over
parsed_url.query, I refactored the extraction into a single loop that processes bothparsed_url.queryandparsed_url.fragment:Using
setdefaultmakes sure any explicitly passed query params always take priority over whatever was embedded in the URL.Testing
Added
test_prepare_request_params_fragment_params_become_query_paramswhich uses a realistic Google Cloud integration URL containing both a query string param and a fragment param. Verifies both end up inquery_paramsand the final URL has no leftover?or#.