Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "keep_blank_values" to experimental_get_query_params() #7416

Closed
2 tasks done
Asaurus1 opened this issue Sep 24, 2023 · 4 comments · Fixed by #7601
Closed
2 tasks done

Add a "keep_blank_values" to experimental_get_query_params() #7416

Asaurus1 opened this issue Sep 24, 2023 · 4 comments · Fixed by #7601
Labels
feature:query-params type:enhancement Requests for feature enhancements or new features

Comments

@Asaurus1
Copy link
Contributor

Checklist

  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.

Summary

With the changes made on #7313 to allow "None" values in text box elements, there is now a potential motivation to pass in empty string values via the URL query params. Current implementation of experimental_get_query_params() does not expose the keep_blank_values argument of urllib.parse.parse_qs as an option, and so query strings like

?foo=&bar=helloworld

are parse as {"bar": "helloworld"} instead of {"bar": "helloworld", "foo": ""}

Why?

I am willing to submit a PR for this, since it impacts my streamlit_qs library. Currently I have to re-implement a special version of experimental_get_query_params that exposes this variable.

How?

Add a keep_blank_values argument to experimental_get_query_params which passes this onto parse_qs.

Additional Context

No response

@Asaurus1 Asaurus1 added the type:enhancement Requests for feature enhancements or new features label Sep 24, 2023
@github-actions
Copy link

To help Streamlit prioritize this feature, react with a 👍 (thumbs up emoji) to the initial post.

Your vote helps us identify which enhancements matter most to our users.

Visits

@sfc-gh-jcarroll
Copy link
Collaborator

Hey @Asaurus1 , thanks for the writeup on this! We are planning to revamp query params to a dict-style interface more similar to session_state in the near future (expected before the end of the year) and will see how we can incorporate this support in that work. It makes sense that we should make this work.

Given that, I'd rather not add more complexity in the very short term to the current experimental version if you have a workaround, but open to hear feedback / discuss more.

@jrieke
Copy link
Collaborator

jrieke commented Sep 26, 2023

Maybe we can just set the values to None in the new API if they are empty in the URL? This would also nicely match what we're doing for widgets with empty state (and probably solve the original problem here pretty elegantly).

@Asaurus1
Copy link
Contributor Author

Maybe we can just set the values to None in the new API if they are empty in the URL? This would also nicely match what we're doing for widgets with empty state (and probably solve the original problem here pretty elegantly).

You'd need to solve the problem where some widgets variably return an empty string to represent no value, or None. How would you represent an empty string vs 'none' in query params this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:query-params type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants