Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#31098 closed Bug (invalid)

has_add_permission() takes 2 positional arguments but 3 were given.

Reported by: Mihai Zamfir Owned by: nobody
Component: contrib.admin Version: 3.0
Severity: Normal Keywords: admin inlines permission
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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

Change History (6)

comment:1 Changed 2 years ago 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.

comment:2 Changed 2 years ago by Mariusz Felisiak

Resolution: invalid
Status: newclosed
Summary: has_add_permission() takes 2 positional arguments but 3 were givenhas_add_permission() takes 2 positional arguments but 3 were given.

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+.

comment:3 Changed 2 years ago by Mihai Zamfir

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

comment:4 Changed 2 years ago by Mariusz Felisiak

You should fix has_add_permission() for your inlines.

comment:5 Changed 2 years ago 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)

comment:6 in reply to:  5 Changed 2 years ago by Mariusz Felisiak

Replying to 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 support channels.

Note: See TracTickets for help on using tickets.
Back to Top