Code

Opened 2 years ago

Closed 20 months ago

#17911 closed Bug (fixed)

Admin change page does not "map" None choices when they are readonly

Reported by: justin.r.donnelly@… Owned by: edwtjo
Component: contrib.admin Version: 1.3
Severity: Normal Keywords:
Cc: charette.s@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: yes

Description

The Django admin change page does not "map" None values as per the class' model field choices when the values are readonly. It shows "(None)" (this value comes from EMPTY_CHANGELIST_VALUE) instead. This is demonstrated by the attached screenshot original_helpers_incorrect_change.png. The admin select page properly maps None values based on the class' model field choices. This is demonstrated by the attached screenshot original_helpers_correct_select.png. The change page should display the same value that the select page does. See attached screenshot modified_helpers_correct_change.png for what the admin change page should look like.

This is due to a bug in contrib/admin/helpers.py. The easiest way to fix the bug is to change line 185 of helpers.py from
result_repr = EMPTY_CHANGELIST_VALUE
to
result_repr = display_for_field(value, f)
However, that leaves the if and else branches executing the same statement (kind of weird). I have attached a modified version of helpers.py where that if/elif/else has been rewritten as an if/else.

I have also attached a tarball of an application that demonstrates this bug. The username is "user" and password is "password".

This is my first ticket submission, so I hope I provided everything you need.

Attachments (6)

mysite.tar (70.0 KB) - added by justin.r.donnelly@… 2 years ago.
tarball of project that demonstrates bug
helpers.py (13.0 KB) - added by justin.r.donnelly@… 2 years ago.
modified contrib/admin/helpers.py
original_helpers_correct_select.png (43.3 KB) - added by justin.r.donnelly@… 2 years ago.
Django admin select page with original helpers.py file (correct)
original_helpers_correct_select.2.png (43.3 KB) - added by justin.r.donnelly@… 2 years ago.
Django admin change page with original helpers.py file (incorrect)
modified_helpers_correct_change.png (44.5 KB) - added by justin.r.donnelly@… 2 years ago.
Django admin change page with modified helpers.py file (correct)
helpers_diff.txt (245 bytes) - added by justin.r.donnelly@… 2 years ago.
diff of modified helpers.py file against trunk

Download all attachments as: .zip

Change History (15)

Changed 2 years ago by justin.r.donnelly@…

tarball of project that demonstrates bug

Changed 2 years ago by justin.r.donnelly@…

modified contrib/admin/helpers.py

Changed 2 years ago by justin.r.donnelly@…

Django admin select page with original helpers.py file (correct)

Changed 2 years ago by justin.r.donnelly@…

Django admin change page with original helpers.py file (incorrect)

Changed 2 years ago by justin.r.donnelly@…

Django admin change page with modified helpers.py file (correct)

comment:1 Changed 2 years ago by charettes

  • Cc charette.s@… added
  • Has patch unset
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Can you provide a diff against trunk of helpers.py instead of the modified file? It's easier to review the changes this way.

Changed 2 years ago by justin.r.donnelly@…

diff of modified helpers.py file against trunk

comment:2 Changed 2 years ago by jezdez

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 20 months ago by edwtjo

  • Has patch set
  • Owner changed from nobody to edwtjo
  • Status changed from new to assigned

comment:5 Changed 20 months ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:6 Changed 20 months ago by Julien Phalip <jphalip@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 29d59a879ea5b116cc31a2fd91be1f7562e487c2:

Fixed #17911 -- Ensure that admin readonly fields' display values are shown in change forms when the raw value is None.

comment:7 Changed 20 months ago by Julien Phalip <jphalip@…>

In 7c91b67cfaf4669df55a715e62d891faea796f20:

[1.5.x] Fixed #17911 -- Ensure that admin readonly fields' display values are shown in change forms when the raw value is None.
Backport of 29d59a879ea5b116

comment:8 Changed 20 months ago by akaariai

  • Resolution fixed deleted
  • Status changed from closed to reopened

The added test doesn't work on Oracle, see #19391.

comment:9 Changed 20 months ago by akaariai

  • Resolution set to fixed
  • Status changed from reopened to closed

Sorry, didn't mean to reopen this one.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.