Skip to content

fix(location): map created_at/updated_at API filters to created/updated model fields - #15995

Merged
Maffooch merged 1 commit into
bugfixfrom
cmm/friendly-edison-aske03
Sep 17, 2026
Merged

Maffooch merged 1 commit into
bugfixfrom
cmm/friendly-edison-aske03

Conversation

@Maffooch

Copy link
Copy Markdown
Contributor

Description

GET /api/v2/location/, /api/v2/location_findings/ and /api/v2/location_product_references/ returned HTTP 500 whenever a client filtered or ordered by created_at / updated_at:

django.core.exceptions.FieldError: Cannot resolve keyword 'created_at' into field.
Choices are: ... created ... updated ...

Root cause: CommonFilters (the base for all three Location filtersets) declared the created_at / updated_at datetime 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 from BaseModel, which names them created / updated, so any created_at_after / created_at_before / updated_at_* parameter, or ordering=created_at, hit a nonexistent field and raised FieldError.

The URL filter (/api/v2/url/) inherits the same defect through AbstractedLocationFilter, whose location__created_at / location__updated_at char filters resolved against the nonexistent Location.created_at / Location.updated_at.

Fix: keep the public parameter names stable (created_at / updated_at) but resolve them to the real created / updated model fields. This is done by adding optional model_field_name arguments to the char/datetime filter helpers and tuple support to the ordering-filter helper, then pointing CommonFilters and the location filters at created / 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 production FieldError and passes with the fix. Coverage:

  • created_at / updated_at datetime range filters resolve to created / updated and filter correctly (row included for a surrounding range, excluded for a past-only range) on LocationFilter, LocationFindingReferenceFilter, LocationProductReferenceFilter.
  • ordering=created_at / -created_at / updated_at / -updated_at no longer raise on all three filtersets.
  • The URL filter's inherited location__created_at / location__updated_at char filters no longer raise.

Run locally against Postgres with V3_FEATURE_LOCATIONS=True:

Ran 8 tests ... OK

Existing regression suites still pass: unittests.test_location_filter_join_scoping and unittests.api_v3.test_apiv3_locations (38 tests, OK). ruff check is clean on all changed files.

Documentation

No documentation change required — the created_at / updated_at filter 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

  • Bugfix submitted against the bugfix branch.
  • Code is Ruff compliant.
  • Code is python 3.13 compliant.
  • Tests added to the unit tests.
  • No model changes / no migration required.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MKDtu3G5NC2NQX5ktrbowN


Generated by Claude Code

…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
@Maffooch Maffooch added this to the 3.3.200 milestone Sep 17, 2026 — with Claude
@Maffooch Maffooch added bugfix and removed unittests labels Sep 17, 2026 — with Claude
@Maffooch
Maffooch enabled auto-merge September 17, 2026 19:46
@Maffooch
Maffooch added this pull request to the merge queue Sep 17, 2026
Merged via the queue into bugfix with commit 399632e Sep 17, 2026
48 checks passed
@Maffooch
Maffooch deleted the cmm/friendly-edison-aske03 branch September 17, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants