Feature request: query_string_parameters should never be None
See original GitHub issueUse case
When there are no query string params, app.current_event.query_string_parameters
is None
which is unexpected.
Solution/User Experience
Proper solution is to make it to behave like an empty dict or to be an actual empty dict.
- avoids extra None checks
- removes one point of surprise which was totally unnecessary
Alternative solutions
No response
Acknowledgment
- This feature request meets Lambda Powertools Tenets
- Should this be considered in other Lambda Powertools languages? i.e. Java, TypeScript
Issue Analytics
- State:
- Created a year ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
Caching content based on query string parameters
When you configure CloudFront to cache based on query string parameters, you can take the following steps to reduce the number of requests...
Read more >HttpServletRequest - Get query string parameters, no form data
I like the idea, but there is not always a "=" character in the query string. If parameter value is empty there is...
Read more >Parse JSON-encoded query strings in FastAPI
For example, you can use parse_obj_as(Quarter | None, start_quarter) for optional arguments. Models in query string parameters? I thought ...
Read more >Handling query string parameters with no value in ASP.NET ...
And as it happens, it's not uncommon to see URLs with query strings like this: ?foo , i.e. a key without a value....
Read more >Building requests - Postman Learning Center
Upload a File via POST Request | Postman Level Up. Blog Posts. Introducing the Next-Generation Postman URL Processor. Public Workspaces.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I understand it would be a nicer experience if you could always do
app.current_event.query_string_parameters.get("id")
and not experience his error:However, I see the
or {}
as a good enough solution. Alternatively, you can also useget_query_string_value
. Even if no query parameters have been provided this call will not fail and you can set a default value to return if the value would beNone
.As @a3kov is thinking about it from a web framework perspective, an analogous solution could be a method on the resolver that always returns a
dict
, e.g.,APIGatewayResolver.query_parameters() -> dict
. However, I can’t see a precedent for that kind of thing, and it could be a slippery slope of needing to add methods for accessing other things like path params, headers, etc.Always harder to remove code than to add it:)