question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: query_string_parameters should never be None

See original GitHub issue

Use 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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sthuber90commented, Aug 19, 2022

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:

AttributeError: ‘NoneType’ object has no attribute ‘get’

However, I see the or {} as a good enough solution. Alternatively, you can also use get_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 be None.

# returns ""
app.current_event.get_query_string_value(name="id", default_value="")

# returns "dummy_id"
app.current_event.get_query_string_value(name="id", default_value="dummy_id")
1reaction
peterschuttcommented, Aug 4, 2022

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.

maybe need more customer demand for this, and can update the docs with an or {} when accessing query strings in the meantime

Always harder to remove code than to add it:)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found