#29723 closed Bug (fixed)
Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the obj argument
Reported by: | Aymeric Augustin | Owned by: | Tim Graham |
---|---|---|---|
Component: | contrib.admin | Version: | 2.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The release notes suggest that InlineModelAdmin.has_add_permission() methods that don’t accept obj as the second positional argument will be supported until Django 3.0:
Support for InlineModelAdmin.has_add_permission() methods that don’t accept obj as the second positional argument will be removed in Django 3.0.
This doesn't appear to be true in my experience.
I have this method defined on an InlineModelAdmin:
def has_add_permission(self, request): return False
I'm getting this traceback with Django 2.1:
File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 126. response = self.process_exception_by_middleware(e, request) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 124. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper 607. return self.admin_site.admin_view(view)(*args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view 142. response = view_func(request, *args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 44. response = view_func(request, *args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner 223. return view(request, *args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in add_view 1647. return self.changeform_view(request, None, form_url, extra_context) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 45. return bound_method(*args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view 142. response = view_func(request, *args, **kwargs) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view 1536. return self._changeform_view(request, object_id, form_url, extra_context) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view 1590. formsets, inline_instances = self._create_formsets(request, form.instance, change=False) File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in _create_formsets 1945. for FormSet, inline in self.get_formsets_with_inlines(*get_formsets_args): File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_formsets_with_inlines 795. yield inline.get_formset(request, obj), inline File "/home/ubuntu/.pyenv/versions/3.6.2/envs/cupido/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_formset 2055. can_add = self.has_add_permission(request, obj) if request else True Exception Type: TypeError at /admin/cupido/notification/add/ Exception Value: has_add_permission() takes 2 positional arguments but 3 were given
Change History (7)
comment:1 by , 6 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 6 years ago
Summary: | Backwards-incompatible change of has_add_permission in 2.1 → Backwards-incompatible change of InlineModelAdmin.has_add_permission() in 2.1 |
---|
comment:3 by , 6 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 6 years ago
Has patch: | set |
---|---|
Summary: | Backwards-incompatible change of InlineModelAdmin.has_add_permission() in 2.1 → Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the obj argument |
comment:5 by , 6 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Refs #27991 -- Add obj arg to InlineModelAdmin.has_add_permission()
There's a check to determine how to call has_add_permission():
Looks like this should be applied to the other call sites.
#8936 -- Added a view permission and a read-only admin made the addition of the offending
can_add = self.has_add_permission(request, obj) if request else True
call raising the exception here.