Skip to content

fix(bedrock_agent): fix querystring field resolution - #6777

Merged
leandrodamascena merged 4 commits into
aws-powertools:developfrom
matteofigus:fix-bedrock-agent-comma-parameters
Jun 10, 2025
Merged

leandrodamascena merged 4 commits into
aws-powertools:developfrom
matteofigus:fix-bedrock-agent-comma-parameters

Conversation

@matteofigus

Copy link
Copy Markdown
Member

Issue number: #6520

Summary

Changes

This PR fixes an issue where Bedrock Agent parameters containing commas (like SQL queries) were being truncated because the method was splitting them by commas.

The fix overrides the method in the class to preserve parameter values without splitting them by commas. This ensures that parameters like SQL queries with commas are correctly passed to the handler function.

Added unit and functional tests to verify the fix works correctly.

User experience

Before:
When using a Bedrock Agent with parameters containing commas (like SQL queries), only the part before the first comma was being passed to the handler function.

For example, with a parameter value of "SELECT a.source_name, b.thing FROM table", only "SELECT a.source_name" would be passed to the handler.

After:
The entire parameter value is correctly passed to the handler function, including any commas.

For example, with a parameter value of "SELECT a.source_name, b.thing FROM table", the entire string is passed to the handler.

Checklist

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This fixes issue aws-powertools#6520 where Bedrock Agent parameters containing commas (like SQL queries) were being truncated because the resolved_query_string_parameters method was splitting them by commas.

The fix overrides the resolved_query_string_parameters method in the BedrockAgentEvent class to preserve parameter values without splitting them by commas.
@matteofigus
matteofigus requested a review from a team as a code owner June 5, 2025 23:44
@boring-cyborg boring-cyborg Bot added the tests label Jun 5, 2025
@pull-request-size pull-request-size Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 5, 2025
@github-actions github-actions Bot added the bug Something isn't working label Jun 5, 2025
@codecov

codecov Bot commented Jun 5, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.13%. Comparing base (e1e0f32) to head (46b8147).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6777      +/-   ##
===========================================
- Coverage    96.15%   96.13%   -0.02%     
===========================================
  Files          256      256              
  Lines        12350    12354       +4     
  Branches       916      916              
===========================================
+ Hits         11875    11877       +2     
- Misses         373      375       +2     
  Partials       102      102              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena left a comment

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.

Hi @matteofigus, thanks for submitting this PR! This solves the problem for BedrockResolver, but in other resolvers where we have multiquerystring fields, we have the same problem. For example, if you replace Bedrock Resolver with APIGatewayHttpResolver (of course, changing the payload), you will observe the same problem.

So, with that said, do you want to open a new issue to investigate other resolvers or do you want to address the issue in this same PR? I would prefer the second option, but feel free to make your own decision.

Comment thread aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py Outdated
Comment thread tests/functional/event_handler/_pydantic/test_bedrock_agent.py Outdated
Comment thread tests/functional/event_handler/_pydantic/test_bedrock_agent.py Outdated
Comment thread tests/unit/data_classes/required_dependencies/test_bedrock_agent_event.py Outdated
- Change @cached_property to @Property for resolved_query_string_parameters
- Simplify the functional test by directly returning the query parameter
- Remove redundant unit test
@leandrodamascena leandrodamascena changed the title fix: prevent splitting Bedrock Agent parameters with commas fix(bedrock_agent): fix querystring field resolution Jun 6, 2025

@leandrodamascena leandrodamascena left a comment

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.

Thank you @matteofigus! APPROVED

@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena
leandrodamascena merged commit c94accc into aws-powertools:develop Jun 10, 2025
@matteofigus
matteofigus deleted the fix-bedrock-agent-comma-parameters branch June 10, 2025 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Powertools Bedrock Resolver truncates parameters with commas

2 participants