[Django] #29723: Backwards-incompatible change of has_add_permission in 2.1

61 views
Skip to first unread message

Django

unread,
Aug 29, 2018, 5:46:28 AM8/29/18
to django-...@googlegroups.com
#29723: Backwards-incompatible change of has_add_permission in 2.1
--------------------------------------------+------------------------
Reporter: Aymeric Augustin | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29723>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 29, 2018, 6:31:50 AM8/29/18
to django-...@googlegroups.com
#29723: Backwards-incompatible change of has_add_permission in 2.1
----------------------------------+------------------------------------

Reporter: Aymeric Augustin | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Carlton Gibson):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Refs #27991 -- Add obj arg to InlineModelAdmin.has_add_permission()

There's a check to determine how to call has_add_permission():


{{{
# RemovedInDjango30Warning: obj will be a required argument.
args = get_func_args(inline.has_add_permission)
if 'obj' in args:
inline_has_add_permission =
inline.has_add_permission(request, obj)
else:
inline_has_add_permission =
inline.has_add_permission(request)
}}}

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:1>

Django

unread,
Aug 29, 2018, 6:33:07 AM8/29/18
to django-...@googlegroups.com
#29723: Backwards-incompatible change of InlineModelAdmin.has_add_permission() in
2.1
----------------------------------+------------------------------------

Reporter: Aymeric Augustin | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:2>

Django

unread,
Aug 29, 2018, 3:54:45 PM8/29/18
to django-...@googlegroups.com
#29723: Backwards-incompatible change of InlineModelAdmin.has_add_permission() in
2.1
----------------------------------+--------------------------------------
Reporter: Aymeric Augustin | Owner: Tim Graham
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => assigned
* owner: nobody => Tim Graham


--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:3>

Django

unread,
Aug 29, 2018, 4:49:45 PM8/29/18
to django-...@googlegroups.com
#29723: Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the
obj argument

----------------------------------+--------------------------------------
Reporter: Aymeric Augustin | Owner: Tim Graham
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.1

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/10355 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:4>

Django

unread,
Aug 30, 2018, 5:22:09 AM8/30/18
to django-...@googlegroups.com
#29723: Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the
obj argument
-------------------------------------+-------------------------------------

Reporter: Aymeric Augustin | Owner: Tim
| Graham
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:5>

Django

unread,
Aug 30, 2018, 5:23:37 AM8/30/18
to django-...@googlegroups.com
#29723: Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the
obj argument
-------------------------------------+-------------------------------------
Reporter: Aymeric Augustin | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"fd8a7a5313f5e223212085b2e470e43c0047e066" fd8a7a5]:
{{{
#!CommitTicketReference repository=""
revision="fd8a7a5313f5e223212085b2e470e43c0047e066"
Fixed #29723 -- Fixed crash if InlineModelAdmin.has_add_permission()
doesn't accept the obj argument.

* Refs #27991 -- Added testing for ModelAdmin.get_inline_instances() if
the inline's has_add_permission() doesn't accept 'obj'.

* Fixed #29723 -- Fixed crash if InlineModelAdmin.has_add_permission()
doesn't accept the obj argument.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:6>

Django

unread,
Aug 30, 2018, 5:36:48 AM8/30/18
to django-...@googlegroups.com
#29723: Admin crashes if InlineModelAdmin.has_add_permission() doesn't accept the
obj argument
-------------------------------------+-------------------------------------
Reporter: Aymeric Augustin | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.1

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"152b1d783bfcf1bab8a038999e1f848a1b4384ef" 152b1d78]:
{{{
#!CommitTicketReference repository=""
revision="152b1d783bfcf1bab8a038999e1f848a1b4384ef"
[2.1.x] Fixed #29723 -- Fixed crash if


InlineModelAdmin.has_add_permission() doesn't accept the obj argument.

* Refs #27991 -- Added testing for ModelAdmin.get_inline_instances() if
the inline's has_add_permission() doesn't accept 'obj'.

* Fixed #29723 -- Fixed crash if InlineModelAdmin.has_add_permission()
doesn't accept the obj argument.

Backport of fd8a7a5313f5e223212085b2e470e43c0047e066 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29723#comment:7>

Reply all
Reply to author
Forward
0 new messages