Skip to content

feat(filters): add RangeFilter for inclusive min/max bounds - #37

Open
AssisLuis wants to merge 1 commit into
iklobato:masterfrom
AssisLuis:feat/range-filter
Open

AssisLuis wants to merge 1 commit into
iklobato:masterfrom
AssisLuis:feat/range-filter

Conversation

@AssisLuis

Copy link
Copy Markdown

Filtering so far only supported exact matches, so numeric, date and datetime columns could not be narrowed to an interval without writing a custom backend (the very example the docs used to illustrate BaseFilter).

RangeFilter follows the existing backend contract: whitelist columns in Meta.filtering.ranges and each one accepts ?_min= (col >= value) and ?_max= (col <= value). The two bounds are independent, values are coerced to the column type (int, float/Numeric, date, datetime via ISO 8601), and a bound that cannot be coerced is ignored the same way an unknown ?ordering= field is.

Because a range is meaningless on an unordered column, Meta.filtering.ranges is validated in RestEndpointMeta against the endpoint's declared and auto-injected columns, raising ConfigurationError at class definition time for an unknown field or a String/Boolean one. Reflected endpoints have no declared columns and are skipped.

YAML config gains a matching ranges: key, which auto-selects the backend like fields/search/ordering already do, and RangeFilter is resolvable by name in backends:.

Covered by tests/test_range_filter.py (numeric, datetime, auto-injected columns, ignored params, composition, config validation) plus a YAML auto-selection case; README, docs/advanced/filtering.md, docs/api-reference/filters.md and examples/08_filtering.py updated.

Filtering so far only supported exact matches, so numeric, date and
datetime columns could not be narrowed to an interval without writing a
custom backend (the very example the docs used to illustrate BaseFilter).

RangeFilter follows the existing backend contract: whitelist columns in
Meta.filtering.ranges and each one accepts ?<field>_min= (col >= value)
and ?<field>_max= (col <= value). The two bounds are independent, values
are coerced to the column type (int, float/Numeric, date, datetime via
ISO 8601), and a bound that cannot be coerced is ignored the same way an
unknown ?ordering= field is.

Because a range is meaningless on an unordered column, Meta.filtering.ranges
is validated in RestEndpointMeta against the endpoint's declared and
auto-injected columns, raising ConfigurationError at class definition time
for an unknown field or a String/Boolean one. Reflected endpoints have no
declared columns and are skipped.

YAML config gains a matching ranges: key, which auto-selects the backend
like fields/search/ordering already do, and RangeFilter is resolvable by
name in backends:.

Covered by tests/test_range_filter.py (numeric, datetime, auto-injected
columns, ignored params, composition, config validation) plus a YAML
auto-selection case; README, docs/advanced/filtering.md,
docs/api-reference/filters.md and examples/08_filtering.py updated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant