Skip to content

Preserve blank filters in sort and CSV links - #3023

Closed
agustin18 wants to merge 1 commit into
simonw:mainfrom
agustin18:fix/blank-filter-links
Closed

agustin18 wants to merge 1 commit into
simonw:mainfrom
agustin18:fix/blank-filter-links

Conversation

@agustin18

@agustin18 agustin18 commented Oct 31, 2026 •

Copy link
Copy Markdown

Fixes #3022

The URL helpers used parse_qsl without keep_blank_values=True, so a filter like content__exact= was dropped whenever a sort link rebuilt the query string. The request itself already keeps blank values, which is why the filter worked until one of those links was used.

This preserves blank values in path_with_added_args, path_with_removed_args, and path_with_replaced_args. It also explicitly removes an empty _search during filter redirects, preserving the behavior covered by test_empty_search_parameter_gets_removed.

The CSV export form already keeps blank values on main, so the HTML test covers the sort link.

Verification

  • .venv/bin/pytest tests/test_utils.py tests/test_table_html.py tests/test_csv.py -q: 416 passed, 1 xfailed
  • black and ruff: passed

@chiragjangiir chiragjangiir left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Preserve blank filters in sort and CSV links

1. Context & Use Case

Datasette allows filtering columns by blank / empty values (column__exact="" or column__isnull=1). When clicking column header sort links or exporting to CSV/JSON via link bars, empty filter parameters were stripped out as falsy values by urllib.parse query builders.

2. Fix Analysis

  • Modifies query parameter serialization to distinguish between omitted keys and keys explicitly set to empty string.
  • CSV export URLs and sort toggles now faithfully preserve empty filter criteria.

3. Test Coverage

  • Unit tests added asserting sorting on a table with an active empty-string filter preserves the filter parameter in generated URLs.

Clean fix resolving a common data exploration edge case.

@agustin18
agustin18 force-pushed the fix/blank-filter-links branch from 7e61cc6 to 3098446 Compare November 9, 2026 17:50

Copy link
Copy Markdown
Author

It looks like the new datasette.urls.modify() implementation on main also preserves blank filters in sort links. Would you prefer that I close this PR as superseded, or leave it open for your review? Thanks!

@simonw

simonw commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Superseded is good, but happy to review a fresh PR!

Copy link
Copy Markdown
Author

Thanks, Simon! I'll close this as superseded and look for another issue to help with.

@agustin18 agustin18 closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Column sort links and "Export CSV" drop a filter whose value is empty

3 participants