Opened 8 years ago

Closed 7 years ago

Last modified 6 years ago

#13609 closed (fixed)

Using a non existent template in admin.Inlines produce error when posting the form

Reported by: Lucio Asnaghi Owned by: Jonas Obrist
Component: contrib.admin Version: 1.2-beta
Severity: Keywords: Inline custom template ValidationError ManagementForm data missing tampered
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I'm using some Staked and Tabular Inline with a custom template.

class AppointmentInline(InlineAutocompleteAdmin):
    model = Appointment
    extra = 0
    template = 'my/non/existent/template/tabular.html'

When the template i'm specifying doesn't exists, the inlines doesn't show up in the admin change_form (no error is produced even in DEBUG mode): this way when i post the form data to save the model, i always get an error:

ValidationError at /admin/test/event/1/

Request Method: 	POST
Request URL:
Django Version: 	1.2 beta 1
Exception Type: 	ValidationError
Exception Value: 	

Exception Location: 	.../thirdparty/django-1.2/django/forms/ in _management_form, line 57
Python Executable: 	/usr/bin/python2.6
Python Version: 	2.6.2
Python Path: 	[...]
Server time: 	Tue, 25 May 2010 10:39:10 +0200


../thirdparty/django-1.2/django/forms/  in _management_form

  50. return self.as_table()
  52. def _management_form(self):
  53. """Returns the ManagementForm instance for this FormSet."""
  54. if or self.files:
  55. form = ManagementForm(, auto_id=self.auto_id, prefix=self.prefix)
  56. if not form.is_valid():

  57. raise ValidationError('ManagementForm data is missing or has been tampered with') ...

  58. else:
  59. form = ManagementForm(auto_id=self.auto_id, prefix=self.prefix, initial={
  60. TOTAL_FORM_COUNT: self.total_form_count(),
  61. INITIAL_FORM_COUNT: self.initial_form_count(),
  62. MAX_NUM_FORM_COUNT: self.max_num
  63. })

I think when resolving the template of an inline, django should at least report with an error that the specified template doesn't exists.

Attachments (1)

13609.diff (4.4 KB) - added by Jonas Obrist 7 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 8 years ago by Lucio Asnaghi

Summary: Using a non existent template in admin.Inlines does not notify thatUsing a non existent template in admin.Inlines produce error when posting the form

comment:2 Changed 8 years ago by anonymous

milestone: 2.01.3

comment:3 Changed 8 years ago by Russell Keith-Magee

Component: Core frameworkdjango.contrib.admin
Triage Stage: UnreviewedAccepted

This problem exists because Django's template language silently eats errors, so the call to {% include inline_admin.opts.template %} fails silently if the template doesn't exist.

The solution here is to validate that the template exists when the InlineModelAdmin object is validated -- see django.contrib.admin.validation.validate_inline.

comment:4 Changed 7 years ago by Jonas Obrist

Has patch: set

comment:5 Changed 7 years ago by Jonas Obrist

I've added validation for the template to validate_inline as russellm suggested. I've also added tests for this to the admin_inlines tests.

comment:6 Changed 7 years ago by Jonas Obrist

Owner: changed from nobody to Jonas Obrist

Changed 7 years ago by Jonas Obrist

Attachment: 13609.diff added

comment:7 Changed 7 years ago by Jannis Leidel

Triage Stage: AcceptedReady for checkin

comment:8 Changed 7 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

This has been fixed by the changes in r15413.

comment:9 Changed 6 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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