-
-
Notifications
You must be signed in to change notification settings - Fork 697
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
Columns starting with an underscore behave poorly in filters #1527
Comments
I think the root cause is this hidden form field on https://latest.datasette.io/fixtures/facetable?_facet=_neighborhood&_neighborhood__exact=Downtown <input type="hidden" name="_facet" value="_neighborhood">
<input type="hidden" name="_neighborhood__exact" value="Downtown">
<input type="submit" value="Apply"> |
I started fiddling with a test for this which extracts the def test_exact_parameter_results_in_correct_hidden_fields(app_client):
# https://github.com/simonw/datasette/issues/1527
response = app_client.get(
"/fixtures/facetable?_facet=_neighborhood&_neighborhood__exact=Downtown"
)
# In this case we should NOT have a hidden _neighborhood__exact=Downtown field
form = Soup(response.body, "html.parser").find("form")
selects = [
{
"name": select["name"],
"value": select.select("option[selected]")[0].text
if select.select("option[selected]")
else "",
}
for select in form.findAll("select")
]
inputs = [input.attrs for input in form.findAll("input")]
# Turn those both into a {name: (value, type)} array
form_inputs = {}
form_inputs.update(
{select["name"]: (select["value"], "select") for select in selects}
)
form_inputs.update(
{
input["name"]: (input.get("value"), input["type"])
for input in inputs
if input.get("name")
}
)
assert form_inputs == {
"_filter_column_1": ("_neighborhood", "select"),
"_filter_op_1": ("=", "select"),
"_filter_value_1": ("Downtown", "text"),
"_filter_column": ("", "select"),
"_filter_op": ("", "select"),
"_filter_value": (None, "text"),
"_sort": ("Sort by pk", "select"),
"_sort_by_desc": (None, "checkbox"),
"_facet": ("_neighborhood", "hidden"),
"_neighborhood__exact": ("Downtown", "hidden"),
} The problem is that last hidden field, |
Manually tested this too, looks like that fixed it. |
Found a new case of this bug: click the "Apply" button on https://latest.datasette.io/fixtures/facetable?_sort=pk&_city_id__gt=1 |
That's because that page has this unnecessary hidden form field: <input type="hidden" name="_city_id__gt" value="1"> That field is added by this bit in the template: datasette/datasette/templates/table.html Lines 119 to 122 in 515f8d3
Which is populated here: datasette/datasette/views/table.py Lines 813 to 821 in ace8656
|
Oh! This is because What happens to columns that contain a |
Similar bug to #1525 (and #1506 before it). Start on https://latest.datasette.io/fixtures/facetable?_facet=_neighborhood - then select a neighborhood - then try to remove that filter using the little "x" and submitting the form again.
The text was updated successfully, but these errors were encountered: