fix(location): map created_at/updated_at API filters to created/updated model fields - #15995
Merged
Merged
Conversation
…ed fields
The Location API filtersets (LocationFilter, LocationFindingReferenceFilter,
LocationProductReferenceFilter) and the URL filter's inherited location
timestamp filters exposed created_at/updated_at query parameters (range
filters and ordering keys) that resolved directly against model fields of the
same name. BaseModel actually stores these timestamps as created/updated, so
requests such as GET /api/v2/location/?created_at_after=... raised
FieldError ("Cannot resolve keyword 'created_at' into field") and returned
HTTP 500 to API clients. The location_findings and location_product_reference
endpoints and ordering by these keys were affected the same way.
Map the public created_at/updated_at parameters to the real created/updated
model fields while keeping the parameter names stable: add optional
model_field_name arguments to the char/datetime filter helpers and tuple
support to the ordering-filter helper, then point CommonFilters and the
location filters at created/updated. No schema or migration change.
Add regression tests covering the datetime range filters, ordering, and the
URL endpoint's inherited location timestamp char filters across all affected
filtersets.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MKDtu3G5NC2NQX5ktrbowN
blakeaowens
approved these changes
Sep 17, 2026
devGregA
approved these changes
Sep 17, 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.
Description
GET /api/v2/location/,/api/v2/location_findings/and/api/v2/location_product_references/returned HTTP 500 whenever a client filtered or ordered bycreated_at/updated_at:Root cause:
CommonFilters(the base for all three Location filtersets) declared thecreated_at/updated_atdatetime range filters — and each filterset's ordering list referenced those same keys — resolving them directly against model fields of the same name. The Location models inherit their timestamps fromBaseModel, which names themcreated/updated, so anycreated_at_after/created_at_before/updated_at_*parameter, orordering=created_at, hit a nonexistent field and raisedFieldError.The URL filter (
/api/v2/url/) inherits the same defect throughAbstractedLocationFilter, whoselocation__created_at/location__updated_atchar filters resolved against the nonexistentLocation.created_at/Location.updated_at.Fix: keep the public parameter names stable (
created_at/updated_at) but resolve them to the realcreated/updatedmodel fields. This is done by adding optionalmodel_field_namearguments to the char/datetime filter helpers and tuple support to the ordering-filter helper, then pointingCommonFiltersand the location filters atcreated/updated. The helper changes are additive and backward compatible.No schema change / no migration — this is purely a filter-to-field mapping correction.
Test results
Added
unittests/test_location_filter_timestamp.py(8 tests). Each one fails against the current code with the exact productionFieldErrorand passes with the fix. Coverage:created_at/updated_atdatetime range filters resolve tocreated/updatedand filter correctly (row included for a surrounding range, excluded for a past-only range) onLocationFilter,LocationFindingReferenceFilter,LocationProductReferenceFilter.ordering=created_at/-created_at/updated_at/-updated_atno longer raise on all three filtersets.location__created_at/location__updated_atchar filters no longer raise.Run locally against Postgres with
V3_FEATURE_LOCATIONS=True:Existing regression suites still pass:
unittests.test_location_filter_join_scopingandunittests.api_v3.test_apiv3_locations(38 tests, OK).ruff checkis clean on all changed files.Documentation
No documentation change required — the
created_at/updated_atfilter and ordering parameters were already part of the (auto-generated) API schema; this change makes them function as documented rather than returning a 500.Checklist
bugfixbranch.🤖 Generated with Claude Code
https://claude.ai/code/session_01MKDtu3G5NC2NQX5ktrbowN
Generated by Claude Code