Skip to content

Fix admin Project search 500 (keywords__keyword, not keywords__name) (#1388)#1389

Merged
jonfroehlich merged 1 commit into
masterfrom
1388-admin-project-search-500
Jun 24, 2026
Merged

Fix admin Project search 500 (keywords__keyword, not keywords__name) (#1388)#1389
jonfroehlich merged 1 commit into
masterfrom
1388-admin-project-search-500

Conversation

@jonfroehlich

Copy link
Copy Markdown
Member

Fixes #1388.

Problem

Searching on the Project admin changelist (e.g. /admin/website/project/?q=jon) returns a 500 in production:

FieldError: Unsupported lookup 'name__icontains' for ForeignKey or join on the field not permitted.

Root cause

ProjectAdmin.search_fields included 'keywords__name', but the Keyword model's field is keyword (not name). Django built keywords__name__icontains — an invalid field path — so every Project admin search raised FieldError.

Fix

search_fields: 'keywords__name''keywords__keyword'.

Why tests missed it (and what this PR adds)

The existing project admin test only asserted that search_fields contained a string; it never executed the query, so a bad field path was invisible. This PR adds two tests to test_admin_changelist.py:

  1. test_project_search_executes — targeted regression that runs the project search and forces SQL evaluation. Verified it reproduces the exact prod FieldError with the fix reverted, and passes with it.
  2. AdminSearchExecutesTests — a sweep that runs the search for every ModelAdmin registered on the custom admin site and forces evaluation. This auto-covers admins added in the future against this whole class of bug. The sweep confirms no other admin currently has a bad search-field path.

Testing

python manage.py test website.tests.test_admin_changelist --settings=makeabilitylab.settings_test → 17 passing. No UI changes (admin-only fix), so no Pa11y run needed.

🤖 Generated with Claude Code

…1388)

ProjectAdmin.search_fields pointed at 'keywords__name', but the Keyword
model's field is 'keyword'. Django built 'keywords__name__icontains', an
invalid field path, so every Project admin search raised FieldError
("Unsupported lookup 'name__icontains' for ForeignKey") -> 500
(e.g. /admin/website/project/?q=jon).

The existing project admin test only asserted search_fields *contained* a
string, so it never executed the query and couldn't catch a bad path. Add:

- test_project_search_executes: targeted regression that runs the project
  search and forces SQL evaluation (reproduces the prod FieldError without
  the fix).
- AdminSearchExecutesTests: sweep that runs the search for every ModelAdmin
  registered on the custom admin site, auto-covering future admins against
  this class of bug.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jonfroehlich jonfroehlich merged commit 6af8101 into master Jun 24, 2026
3 checks passed
@jonfroehlich jonfroehlich deleted the 1388-admin-project-search-500 branch June 24, 2026 00:49
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.

Admin Project changelist search 500s (search_fields points at nonexistent 'keywords__name')

1 participant