Fix admin Project search 500 (keywords__keyword, not keywords__name) (#1388)#1389
Merged
Conversation
…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>
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.
Fixes #1388.
Problem
Searching on the Project admin changelist (e.g.
/admin/website/project/?q=jon) returns a 500 in production:Root cause
ProjectAdmin.search_fieldsincluded'keywords__name', but theKeywordmodel's field iskeyword(notname). Django builtkeywords__name__icontains— an invalid field path — so every Project admin search raisedFieldError.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_fieldscontained a string; it never executed the query, so a bad field path was invisible. This PR adds two tests totest_admin_changelist.py:test_project_search_executes— targeted regression that runs the project search and forces SQL evaluation. Verified it reproduces the exact prodFieldErrorwith the fix reverted, and passes with it.AdminSearchExecutesTests— a sweep that runs the search for everyModelAdminregistered 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