[Django] #31098: has_add_permission() takes 2 positional arguments but 3 were given

684 views
Skip to first unread message

Django

unread,
Dec 17, 2019, 10:44:53 AM12/17/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given
-------------------------------------+-------------------------------------
Reporter: androane | Owner: nobody
Type: Bug | Status: new
Component: | Version: 3.0
contrib.admin | Keywords: admin inlines
Severity: Normal | permission
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In n class inheriting from ModelAdmin, I'm doing

{{{
def get_inline_instances(self, request, obj=None):
inline_instances = super().get_inline_instances(request, obj)
...
}}}

and the super call is throwing an error in the source code of Django here:

{{{
def get_inline_instances(self, request, obj=None):
inline_instances = []
for inline_class in self.get_inlines(request, obj):
inline = inline_class(self.model, self.admin_site)
if request:
if not (inline.has_view_or_change_permission(request, obj)
or
inline.has_add_permission(request, obj) or
# AT THIS LINE
inline.has_delete_permission(request, obj)):
continue
if not inline.has_add_permission(request, obj):
inline.max_num = 0
inline_instances.append(inline)

return inline_instances
}}}

Haven't had this problem with Django 2.0

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

Django

unread,
Dec 17, 2019, 12:16:09 PM12/17/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given
-------------------------------------+-------------------------------------
Reporter: androane | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution:
Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Baptiste Mispelon):

This sounds like a duplicate of #29723. Which version of Django do you
have installed exactly?

Could you share the entire code of your `ModelAdmin` definition?

Thanks.

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

Django

unread,
Dec 18, 2019, 2:36:16 AM12/18/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given.
-------------------------------------+-------------------------------------
Reporter: Mihai Zamfir | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: invalid

Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* status: new => closed
* resolution: => invalid


Comment:

Support for `InlineModelAdmin.has_add_permission()` methods that don’t
accept `obj` as the second positional argument was deprecated in Django
2.1 and removed in Django 3.0.

We had a small regression in Django 2.1.0 (see #29723), so you should use
Django 2.1.1+.

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

Django

unread,
Dec 18, 2019, 2:53:07 AM12/18/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given.
-------------------------------------+-------------------------------------
Reporter: Mihai Zamfir | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: invalid
Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Mihai Zamfir):

But what if I want to use Django 3? how do I adapt it?

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

Django

unread,
Dec 18, 2019, 2:59:27 AM12/18/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given.
-------------------------------------+-------------------------------------
Reporter: Mihai Zamfir | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: invalid
Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by felixxm):

You should fix `has_add_permission()` for your inlines.

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

Django

unread,
Dec 18, 2019, 10:25:07 AM12/18/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given.
-------------------------------------+-------------------------------------
Reporter: Mihai Zamfir | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: invalid
Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by Mihai Zamfir):

Thanks for the response. However, that's not something I can control. As
in the snippet above, I'm just calling the parent method, the super call
errors.

{{{
def get_inline_instances(self, request, obj=None):
inline_instances = super().get_inline_instances(request, obj)
}}}

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

Django

unread,
Dec 18, 2019, 2:06:37 PM12/18/19
to django-...@googlegroups.com
#31098: has_add_permission() takes 2 positional arguments but 3 were given.
-------------------------------------+-------------------------------------
Reporter: Mihai Zamfir | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.0
Severity: Normal | Resolution: invalid
Keywords: admin inlines | Triage Stage:
permission | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Comment (by felixxm):

Replying to [comment:5 Mihai Zamfir]:


> Thanks for the response. However, that's not something I can control. As
in the snippet above, I'm just calling the parent method, the super call
errors.
>
> {{{

> def get_inline_instances(self, request, obj=None):
> inline_instances = super().get_inline_instances(request, obj)
> }}}

Of course you can, your class that inherits from `ModelAdmin` has inlines
with a custom `has_add_permission()` method that doesn't accept `obj`
argument. Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels].

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

Reply all
Reply to author
Forward
0 new messages