Fix facet selection for explicit exact filters

`colname__exact=value` is now treated the same as `colname=value` when determining which facets are selected.

Closes #1695
This commit is contained in:
Simon Willison 2026-09-16 14:56:09 -07:00 • committed by GitHub
commit d2098e9f84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 91 additions and 2 deletions

View file

@ -484,6 +484,31 @@ async def test_facet_display(ds_client):
]
@pytest.mark.asyncio
@pytest.mark.parametrize(
"filters", ["state=CA", "state__exact=CA", "state=CA&state__exact=CA"]
)
async def test_facet_remove_exact_filter(ds_client, filters):
response = await ds_client.get(
f"/fixtures/facetable?_facet=state&{filters}&on_earth=1"
)
assert response.status_code == 200
soup = Soup(response.text, "html.parser")
remove_link = soup.select_one('.facet-info[data-column="state"] li a.cross')
assert remove_link is not None
url = urllib.parse.urlsplit(remove_link["href"])
assert urllib.parse.parse_qsl(url.query) == [
("_facet", "state"),
("on_earth", "1"),
]
unfiltered = await ds_client.get(f"{url.path}.json?{url.query}")
assert unfiltered.status_code == 200
rows = unfiltered.json()["rows"]
assert len(rows) == 14
assert all(row["on_earth"] == 1 for row in rows)
assert {row["state"] for row in rows} == {"CA", "MI"}
@pytest.mark.asyncio
async def test_facets_persist_through_filter_form(ds_client):
response = await ds_client.get(