Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#13609 closed (fixed)

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

Reported by: kunitoki Owned by: ojii
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 ojii 5 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 6 years ago by kunitoki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Using a non existent template in admin.Inlines does not notify that to Using a non existent template in admin.Inlines produce error when posting the form

comment:2 Changed 6 years ago by anonymous

  • milestone changed from 2.0 to 1.3

comment:3 Changed 6 years ago by russellm

  • Component changed from Core framework to django.contrib.admin
  • Triage Stage changed from Unreviewed to Accepted

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 5 years ago by ojii

  • Has patch set

comment:5 Changed 5 years ago by ojii

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 5 years ago by ojii

  • Owner changed from nobody to ojii

Changed 5 years ago by ojii

comment:7 Changed 5 years ago by jezdez

  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 5 years ago by russellm

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

This has been fixed by the changes in r15413.

comment:9 Changed 5 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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