Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30050 closed Bug (fixed)

InlineModelAdmin.has_change_permission() incorrectly called with non-None obj during add

Reported by: Andrea Angelini Owned by: nobody
Component: contrib.admin Version: 2.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Andrea Angelini)

Fine with Django 2.1.3, bug with Django 2.1.4.

If I have an admin Inline of a Model, with fk to a ParentModel, when I try to add a new ParentModel in the admin panel ("/admin/foo/parentmodel/add/"), the Inline has_change_permission is called 3 times instead of 2, after this commit:

https://github.com/django/django/commit/27f5b0aff3442e5c25e84972dff4f5fe1edd4e68

at line 1962 has_change_permission is passed an obj that is not None.

Before this commit, obj was None both of the times, now it's None the first time, an empty instance of ParentModel the second time, and None the third time.

Line 1962 should be something like:

permission_obj = obj if change else None
if not inline.has_change_permission(request, permission_obj):

Change History (5)

comment:1 by Andrea Angelini, 6 years ago

Description: modified (diff)
Last edited 6 years ago by Tim Graham (previous) (diff)

comment:2 by Tim Graham, 6 years ago

Severity: NormalRelease blocker
Summary: admin.TabularInline has_change_permission obj is not None on addInlineModelAdmin.has_change_permission() incorrectly called with non-None obj during add
Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 6 years ago

Has patch: set

comment:4 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: newclosed

In 02c07be9:

Fixed #30050 -- Fixed InlineModelAdmin.has_change_permission() called with non-None obj during add.

Thanks andreage for the report and suggested fix.

comment:5 by Tim Graham <timograham@…>, 6 years ago

In 4e4b9521:

[2.1.x] Fixed #30050 -- Fixed InlineModelAdmin.has_change_permission() called with non-None obj during add.

Thanks andreage for the report and suggested fix.

Backport of 02c07be95c47efaab9da7422c33ee76142f11336 from master.

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