Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13004 closed (fixed)

The new get_readonly_fields() method of the ModelAdmin breaks with many to many fields

Reported by: hejsan Owned by: nobody
Component: contrib.admin Version: 1.2-beta
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

This breaks if a ManyToMany field is specified as readonly.

This is because the contents() function that is called in the fieldset.html template tries to display the value of the field but gets a ValueError if it is a ManyToManyField because they can't be used: "[Model name] instance needs to have a primary key value before a many-to-many relationship can be used"

Just need to add ValueError to the catch as seen in the patch I attached, called catch_value_error.diff.
Hope it gets merged before beta 2.

Attachments (2)

catch_value_error.diff (609 bytes) - added by hejsan 4 years ago.
Very simple fix, just catch one more Exception
catch_error_with_test-12818.diff (2.2 KB) - added by mlavin 4 years ago.
Added a basic regression test along with the orginal patch.

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by hejsan

Very simple fix, just catch one more Exception

comment:1 Changed 4 years ago by hejsan

  • Component changed from Uncategorized to Contrib apps
  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.1 to 1.2-beta

comment:2 Changed 4 years ago by russellm

  • Component changed from Contrib apps to django.contrib.admin
  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by mlavin

Added a basic regression test along with the orginal patch.

comment:3 Changed 4 years ago by kmtracey

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

(In [12827]) Fixed #13004: Ensure the add page for a model with a ManyToManyField specified
in readonly_fields does not raise an exception. Thanks hejsan, mlavin, copelco.

comment:4 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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.