Fix actions listed but not executable via action_ tool#73
Merged
Conversation
…xecution Fixes #69 — actions listed by actions_<model> were not found when executing via action_<model>. The root cause was that handle_action iterated the raw model_admin.actions list and checked callable(action), which skipped string-referenced method actions (a standard Django pattern). Replaced manual action iteration with ModelAdmin.get_actions(request) which properly resolves string references, includes global actions, and filters by user permissions.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
7tg
commented
Feb 8, 2026
| self.method = "GET" | ||
| self.path = "/" | ||
| self.META = {} | ||
| self.META = {"SCRIPT_NAME": ""} |
Owner
Author
There was a problem hiding this comment.
Django's AdminSite.each_context(request) accesses request.META["SCRIPT_NAME"] directly (not .get()), which raises a KeyError when META is empty. This is reached through get_actions(request) → _filter_actions_by_permissions for certain built-in actions like delete_selected. Adding SCRIPT_NAME: "" prevents that crash while keeping the request lightweight.
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.
Summary
actions_<model>returned "not found" when executing viaaction_<model>handle_actioniterated rawmodel_admin.actionsand checkedcallable(action), which skipped string-referenced method actions (a standard Django pattern likeactions = ["set_status_disabled"])ModelAdmin.get_actions(request)which properly resolves string references, includes globally-registered actions, and filters by user permissionsTest plan
test_listed_string_action_can_be_executedreproduces the exact bug from the issue (string-referenced action listed but not executable)ruff check,ruff-format,mypyall pass)