While in the admin, if you have a form with inline formsets and you try to
do a save as new, it works properly, unless there is a validation error.
If you get a validation error, Django sends you through the add_view which
no longer as the "Save as new" option. If you click save here, you will
get the error below:
ValueError at /admin/drawings/sow/add/
invalid literal for int() with base 10: ''
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/drawings/sow/add/
Django Version: 1.6.6.dev20140829183230
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: ''
Exception Location:
/Users/tip/Dropbox/websites/isotekrms/django/db/models/fields/__init__.py
in get_prep_value, line 613
Python Executable:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
I, have written a small patch that will check to see if the formset had
validation errors and it was submitted as a save as new, it will set the
context variable change=True which causes the "Save as new" button to show
on the form again. Fixing the validation errors on the screen and
pressing "Save as new" again will save the form properly.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_better_patch: => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:1>
Old description:
New description:
This bug seems to have been around for a long time, as I've tried this
from version 1.4 up.
While in the admin, if you have a form with inline formsets and you try to
do a save as new, it works properly, unless there is a validation error.
If you get a validation error, Django sends you through the add_view which
no longer has the "Save as new" option. If you click save here, you will
get the error below:
ValueError at /admin/drawings/sow/add/
invalid literal for int() with base 10: ''
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/drawings/sow/add/
Django Version: 1.6.6.dev20140829183230
Exception Type: ValueError
Exception Value:
invalid literal for int() with base 10: ''
Exception Location:
/Users/tip/Dropbox/websites/isotekrms/django/db/models/fields/__init__.py
in get_prep_value, line 613
Python Executable:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
I, have written a small patch that will check to see if the formset had
validation errors and it was submitted as a save as new, it will set the
context variable change=True which causes the "Save as new" button to show
on the form again. Fixing the validation errors on the screen and
pressing "Save as new" again will save the form properly.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:2>
* needs_tests: 0 => 1
* stage: Unreviewed => Accepted
Comment:
The patch also requires tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:3>
* owner: nobody => raulcd
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:4>
Comment (by johnrtipton):
Updated patch to hide "Save" and "Save and Continue" buttons after a
validation error when try to Save as New.
If you try to Save as New and get a validation error, you must hit Save as
New again or you will get the previously mentioned error.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:5>
* owner: raulcd =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:6>
* owner: => jayadeepk
* cc: karnatijayadeep@… (added)
* version: 1.6 => master
* status: new => assigned
Comment:
The bug is reproducible in master version.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:7>
* owner: jayadeepk => tino
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:8>
Comment (by tino):
There is a problem with "Save as new" and validation errors in general.
When you click "Save as new" and a validation error is raised, the
`ModelAdmin.add_view` is returned, which does not include the "Save as
new" button, but the other save buttons. The url is still the change url
of the original object. This is confusing, as all the normal save buttons
work as "Save as new" buttons now.
I would suggest that in that case, we should only show the "Save as new"
button, and hide the others, as was proposed earlier in this patch.
If we would have to go in the direction to keep the other save buttons
(''and'' the "Save as new" button, all with correct functionality), the
fix for the underlying issue with the inline formsets is not easy. You
would have to validate both the object and it's inline instances
(https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1367),
and if either fails, reset the inline instances to instances where
`save_as_new` is False.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:9>
* needs_tests: 1 => 0
Comment:
All right, created a pull request in the direction that the original
author took: https://github.com/django/django/pull/4265
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:10>
* needs_better_patch: 0 => 1
Comment:
PR reviewed.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:11>
Comment (by adamzap):
tino, I'd be happy to address Tim's comments on your pull request and
finish the ticket if you don't have the time right now.
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:12>
* owner: tino => adamzap
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:13>
Comment (by adamzap):
I submitted a new pull request that addresses Tim's comments:
https://github.com/django/django/pull/4559
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:14>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:15>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:16>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"0894643e40327e48397573b7844585618200442b" 0894643e]:
{{{
#!CommitTicketReference repository=""
revision="0894643e40327e48397573b7844585618200442b"
Fixed #23387 -- Kept "Save as new" button after validation errors in
admin.
When "Save as new" is chosen and errors occur, only show the "Save as new"
button and not the other save buttons.
Thanks to Tino de Bruijn for doing the real work on this fix.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/23387#comment:17>