Opened 5 years ago

Closed 5 years ago

Last modified 5 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 by Baptiste Mispelon, 5 years ago

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 by Mariusz Felisiak, 5 years ago

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 by Mihai Zamfir, 5 years ago

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

comment:4 by Mariusz Felisiak, 5 years ago

You should fix has_add_permission() for your inlines.

comment:5 by Mihai Zamfir, 5 years ago

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)

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

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