Repository navigation
Filters match numbers in columns with no declared type - #3111
Merged
Merged
Conversation
A column in a view that is calculated by an expression, such as
count(*) or sum(amount), has no type affinity. SQLite does not convert
the text value from the query string to a number when comparing against
it, so ?total=5 returned no rows and facet links led to empty pages.
For columns with no declared type, the exact, not, in and notin filters
now compare a value that looks like a number as both text and a number:
"total" in (:p0, cast(:p0 as numeric))
Columns with a declared type get the same SQL as before.
Closes #2073, closes #2713
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3111 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 81 81
Lines 14582 14612 +30
=====================================
- Misses 14582 14612 +30 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Owner
Author
|
We need a view in |
The view has three columns calculated by aggregate functions, which have no declared type: row_count, planet_total and avg_on_earth. The filter and facet link tests now use it in place of a database of their own. One smaller in-memory test stays for cases the fixtures have no data for: untyped table columns, text that looks like a number and numbers that are not whole. test_database_list_respects_view_table asks for ?database=data, so it no longer depends on how many items the fixtures put on the homepage. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
simonw
added a commit
that referenced
this pull request
Nov 23, 2026
Refs #1048, #1342, #1479, #1553, #1611, #1627, #1630, #1671, #1674, #1822, #1841, #1873, #1914, #1919, #1973, #2045, #2073, #2145, #2253, #2356, #2419, #2713, #2805, #2807, #2810, #2826, #2942, #2967, #3070, #3074, #3075, #3078, #3079, #3081, #3082, #3083, #3084, #3085, #3087, #3088, #3089, #3090, #3091, #3092, #3093, #3097, #3098, #3099, #3100, #3101, #3102, #3103, #3104, #3105, #3106, #3107, #3108, #3109, #3111, #3112, #3113, #3115
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes:
A column in a view that is calculated by an expression, such as
count(*)orsum(amount), has no type affinity. SQLite does not convert the text value from the query string to a number when comparing against it, so?total=5returned no rows even when every row had atotalof 5. Facet links are?column=valuefilters, so facets on those columns linked to empty pages.The fix
For columns with no declared type, and only for values that look like numbers, the
exact,not,inandnotinfilters now compare the value as both text and a number:Claude Fable 5.2 Medium
inform is deliberate."total" = cast(:p0 as numeric)would apply numeric affinity to the column too, so?col=1would also match the text'1.0', and it stops SQLite using an index on the column.__gt,__gte,__ltand__ltealready worked, because those convert the value in Python._table_filters()looks up the column types only when the request has filter arguments. That lookup is served from the schema cache added in #3102.Behaviour changes to be aware of
?column=1on such a column now matches the number1as well as the text"1". It previously matched only the text.1, real1.0, text'1'), each of its facet links now returns all of those rows, which is more than the count shown beside the link. A facet link cannot say which type it means. Onmainthe text links were right and the number link returned too few rows.Testing
I ran 16 filter URLs and 14 facet links against a view with
sum(),count(),avg(), acaseexpression and a text column, plus typed and untyped table columns:mainThe fixtures database has a new view,
facetable_by_state, with three columns calculated by aggregate functions:/fixtures/facetable_by_state?row_count=4returns no rows onmainand theMIrow with this change.Tests in
tests/test_filters.py:Three existing tests changed because of the new view: two lists of fixture views, and
test_database_list_respects_view_table, which now asks for?database=dataso that it does not depend on how many items the fixtures put on the homepage.The full suite passes locally (3,727 passed).
Other PRs for these issues
exactandnotonly, and no longer applies tomain.This PR is based on a patch from the 1.0 milestone review, rebased onto
main.🤖 Generated with Claude Code