Opened 8 years ago

Closed 8 years ago

#26681 closed Bug (duplicate)

save_as=True and inlines in ModelAdmin raises ValidationError

Reported by: Andreas Stocker Owned by: nobody
Component: contrib.admin Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ModelAdmin raises a ValidationError exception when trying to save after the first time trying to save with "Save as new" failed with form errors. The exception message is [u"'' value must be an integer."]

Steps to reproduce:

1.) Register a ModelAdmin with inlines:

class MyStackedInline(admin.StackedInline):
    model = MyInlineModel
    extra = 1

class MyAdmin(admin.ModelAdmin):
    inlines = [MyStackedInline, ]
    save_as = True

admin.site.register(MyModel, MyAdmin)

2.) Go to the admin panel, open an existing MyModel object and change the form contents in a way that causes form errors (e.g. keep an required field blank).
3.) Click on the "Save as new" button.
4.) The form now shows the validation errors. Fix them and click on the "Save and add another" button. Notice there is no "Save as new" button any more, though save_as=True.
5.) The admin panel now raises the ValidationError exception.

Stacktrace:

File "/my/app/venv/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  618.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  57.         response = view_func(request, *args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  233.             return view(request, *args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
  1518.         return self.changeform_view(request, None, form_url, extra_context)
File "/my/app/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  34.             return bound_func(*args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  110.                     response = view_func(request, *args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  30.                 return func.__get__(self, type(self))(*args2, **kwargs2)
File "/my/app/venv/lib/python2.7/site-packages/django/utils/decorators.py" in inner
  145.                     return func(*args, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/contrib/admin/options.py" in changeform_view
  1468.             if all_valid(formsets) and form_validated:
File "/my/app/venv/lib/python2.7/site-packages/django/forms/formsets.py" in all_valid
  439.         if not formset.is_valid():
File "/my/app/venv/lib/python2.7/site-packages/django/forms/formsets.py" in is_valid
  304.         self.errors
File "/my/app/venv/lib/python2.7/site-packages/django/forms/formsets.py" in errors
  278.             self.full_clean()
File "/my/app/venv/lib/python2.7/site-packages/django/forms/formsets.py" in full_clean
  326.             form = self.forms[i]
File "/my/app/venv/lib/python2.7/site-packages/django/utils/functional.py" in __get__
  59.         res = instance.__dict__[self.name] = self.func(instance)
File "/my/app/venv/lib/python2.7/site-packages/django/forms/formsets.py" in forms
  142.         forms = [self._construct_form(i) for i in range(self.total_form_count())]
File "/my/app/venv/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  868.         form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
File "/my/app/venv/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
  586.             pk = to_python(pk)
File "/my/app/venv/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in to_python
  969.                 params={'value': value},

Exception Type: ValidationError at /admin/myapp/mymodel/add/
Exception Value: [u"'' value must be an integer."]

Change History (3)

comment:1 by Tim Graham, 8 years ago

Have you tested with Django 1.9 or 1.10a1? This might be a duplicate of #23387 which is fixed in 1.9.

comment:2 by Andreas Stocker, 8 years ago

I've tested it now in Django 1.9 and the bug does not occur there. In fact, Django 1.9 does exactly the same thing I am doing for my application (by overriding the admin/submit_line.html template to use my own implementation of the submit_row tag).

As Django 1.8 is an long-term support release, I'll guess the fix should be backported. Upgrading to a non-LTS release is at least not an option for me.

Version 0, edited 8 years ago by Andreas Stocker (next)

comment:3 by Tim Graham, 8 years ago

Resolution: duplicate
Status: newclosed

Sorry, but per our supported versions policy, 1.8 is only receiving security fixes and data loss issues.

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