-
Notifications
You must be signed in to change notification settings - Fork 453
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationnot-a-bugpending-releaseFix or implementation already in dev waiting to be releasedFix or implementation already in dev waiting to be released
Description
Expected Behaviour
A correctly raised exception with a descriptive message. For example:
TypeError: Query param value must be a string
Current Behaviour
When using enable_validation=True
and declaring integer query params in routes, passing string values results in the following error:
return {k: v.split(",") for k, v in self.query_string_parameters.items()}
^^^^^^^
AttributeError: 'int' object has no attribute 'split'
This is really misleading and forces the developer to dig into Powertools source code to determine what is going on.
Code snippet
#### App Code
app = APIGatewayRestResolver(enabled_validation=True)
@app.get("/todos")
def get_todos(page_num: Annotated[int, Query()] = None):
pass
#### Test Code
event = {
# ...
"queryStringParameters": {"page_num": 5} # <-- Integer value
}
Possible Solution
It looks like Powertools assumes values to be strings, based on the usage of split()
. If so, then we should probably raise a TypeError
when encountering a query param value that is not a string prior to automatically splitting.
Steps to Reproduce
See Code Snippet
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.9
Packaging format used
PyPi
Debugging logs
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationnot-a-bugpending-releaseFix or implementation already in dev waiting to be releasedFix or implementation already in dev waiting to be released
Type
Projects
Status
Coming soon