Opened 15 years ago

Closed 14 years ago

Last modified 13 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: no UI/UX: no

Description

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: 	http://127.0.0.1:8000/admin/test/event/1/
Django Version: 	1.2 beta 1
Exception Type: 	ValidationError
Exception Value: 	

Exception Location: 	.../thirdparty/django-1.2/django/forms/formsets.py 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/formsets.py  in _management_form

  50. return self.as_table()
  51.
  52. def _management_form(self):
  53. """Returns the ManagementForm instance for this FormSet."""
  54. if self.data or self.files:
  55. form = ManagementForm(self.data, 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 14 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by Lucio Asnaghi, 15 years ago

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 by anonymous, 14 years ago

milestone: 2.01.3

comment:3 by Russell Keith-Magee, 14 years ago

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 by Jonas Obrist, 14 years ago

Has patch: set

comment:5 by Jonas Obrist, 14 years ago

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 by Jonas Obrist, 14 years ago

Owner: changed from nobody to Jonas Obrist

by Jonas Obrist, 14 years ago

Attachment: 13609.diff added

comment:7 by Jannis Leidel, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

This has been fixed by the changes in r15413.

comment:9 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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