Skip to content

Drop write validators from generated filter schemas - #44

Merged
zedrdave merged 2 commits into
mainfrom
fix/filter-schema-drops-write-validators
Aug 30, 2026
Merged

zedrdave merged 2 commits into
mainfrom
fix/filter-schema-drops-write-validators

Conversation

@zedrdave

Copy link
Copy Markdown
Member

Problem

generate_filter_schema clones base-schema fields together with their validate= chain, so query filter parameters inherit write-time rules (Regexp, Length, Range, custom callables). When a validator is added after rows already hold non-conforming values, filtering by the stored value returns 422 — the rows become unreachable through the very filter meant to find them.

Concrete case: iaoport added an IMO format+checksum validator to VesselAutoSchema; a pre-existing row with imo='23573' can no longer be looked up via GET /api/vessel/?imo=23573.

Fix

_clone_field now clears validators on every cloned filter field — preserved equality fields and __from/__to/__min/__max variants alike. Filtering by an arbitrary value is always safe: it simply matches nothing. Field-type coercion still applies, and the page/page_size bounds are defined separately and unaffected.

Tests

New unit test covers the preserved equality field (Regexp + custom checksum callable) and the suffixed numeric clones (Range). Full suite green.

generate_filter_schema cloned base-schema fields together with their
validate= chain, so a query filter inherited write-time rules (Regexp,
Length, Range, custom callables). Filtering by a stored value that
predates a newly added rule then returned 422, making those rows
unreachable through the very filter that should find them.

_clone_field now clears validators on every cloned filter field:
preserved equality fields and __from/__to/__min/__max variants alike.
Filtering by an arbitrary value is always safe (it matches nothing);
field-type coercion still applies, and the page/page_size bounds are
defined separately and unaffected.
@zedrdave
zedrdave merged commit 2977765 into main Aug 30, 2026
9 checks passed
@zedrdave
zedrdave deleted the fix/filter-schema-drops-write-validators branch August 30, 2026 07:28
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