Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32728 closed Bug (duplicate)

Primary key column is duplicated in the admin changelist when it's in ModelAdmin.list_editable.

Reported by: Greenbond Owned by: nobody
Component: contrib.admin Version: 3.2
Severity: Normal Keywords: primary_key, list_editable
Cc: Greenbond Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description (last modified by Greenbond)

I found a suspicious bug in admin site.

Config ( Conditions )

  1. You have a primary_key =True field in your model.py
  1. Primary_key = True field is included in list_editable option in your admins.py

The primary_key = True field you set in the list_editable will be dupulicated in your admin site.

I created a public repository in github to test or check easily.
There is a screenshot for the suspicious bug and sample codings in the Readme on github.

https://github.com/Greenbond/Bugreport

Change History (4)

comment:1 by Greenbond, 3 years ago

Description: modified (diff)

comment:2 by Greenbond, 3 years ago

Cc: Greenbond added

comment:3 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed
Summary: Dupulicated column in admin sitePrimary key column is duplicated in the admin changelist when it's in ModelAdmin.list_editable.

Thanks for the report. Including primary keys in the ModelAdmin.list_editable will not work as you expect, see #2259. We could easily fix an issue with duplicated columns:

diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py
index 86eade6fed..69bbb53d94 100644
--- a/django/contrib/admin/templatetags/admin_list.py
+++ b/django/contrib/admin/templatetags/admin_list.py
@@ -260,7 +260,7 @@ def items_for_result(cl, result, form):
                 bf = form[field_name]
                 result_repr = mark_safe(str(bf.errors) + str(bf))
             yield format_html('<td{}>{}</td>', row_class, result_repr)
-    if form and not form[cl.model._meta.pk.name].is_hidden:
+    if form and not form[cl.model._meta.pk.name].is_hidden and cl.model._meta.pk.name not in form.fields:
         yield format_html('<td>{}</td>', form[cl.model._meta.pk.name])

however it won't fix the main issue described in #2259. IMO including primary keys in ModelAdmin.list_editable should not be allowed. Closing as a duplicate of #2259.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In dcebc5da:

Refs #2259 -- Disallowed primary keys in ModelAdmin.list_editable.

Refs #32728.

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