[Django] #17417: "Save as new" is buggy when a ValidationError is raised

19 views
Skip to first unread message

Django

unread,
Dec 15, 2011, 12:21:45 PM12/15/11
to django-...@googlegroups.com
#17417: "Save as new" is buggy when a ValidationError is raised
--------------------------------+----------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.3
Severity: Normal | Keywords: save_as unique
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+----------------------------
We use `save_as = True` for several of our models on a news site I
maintain. Each model has a unique "slug" field. If you press "Save as New"
without changing the slug field a ValidationError is raised, and the for
is displayed to the user with a warning (as it should). However, the url
is that of the old entity, the "Save as New" button is replaced with "Save
and Add Another" and all three buttons raise an ValueError (trying to
int() an empty string, presumably the id).

--
Ticket URL: <https://code.djangoproject.com/ticket/17417>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 16, 2011, 8:55:01 AM12/16/11
to django-...@googlegroups.com
#17417: "Save as new" is buggy when a ValidationError is raised
--------------------------------+--------------------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution: duplicate
Keywords: save_as unique | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by anonymous):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

Duplicate of #13223. See also #5681.

--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:1>

Django

unread,
Dec 16, 2011, 10:41:08 AM12/16/11
to django-...@googlegroups.com
#17417: "Save as new" is buggy when a ValidationError is raised
--------------------------------+--------------------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: reopened
Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution:
Keywords: save_as unique | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by ramiro):

* status: closed => reopened
* resolution: duplicate =>


--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:2>

Django

unread,
Dec 16, 2011, 10:56:28 AM12/16/11
to django-...@googlegroups.com
#17417: "Save as new" is buggy when a ValidationError is raised
--------------------------------+--------------------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution: worksforme
Keywords: save_as unique | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by ramiro):

* status: reopened => closed
* resolution: => worksforme


Comment:

(sorry, anonymous user above was me)

Wait, the OP doesn't mention inlines so this isn't a duplicate of #13223.

But I can't reproduce the reported error with this simple model

{{{
class Article(models.Model):
title = models.CharField(max_length=30)
slug = models.CharField(max_length=200, unique=True)

def __unicode__(self):
return self.title
}}}

and ModelAdmin

{{{
class ArticleAdmin(admin.ModelAdmin):
save_as = True


admin.site.register(Article, ArticleAdmin)
}}}

(tested this with 1.3 and trunk)

--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:3>

Django

unread,
Jun 18, 2012, 5:16:56 AM6/18/12
to django-...@googlegroups.com
#17417: "Save as new" does not work when a ValidationError is raised
--------------------------------+------------------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: reopened
Component: contrib.admin | Version: master
Severity: Normal | Resolution:
Keywords: save_as unique | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by gregmuellegger):

* status: closed => reopened

* needs_better_patch: 0 => 1
* version: 1.3 => master
* resolution: worksforme =>
* stage: Unreviewed => Accepted


Comment:

This bug is valid, and I have a proof for that :) (see attached testcase).

The form is not showing the "save as new" button after a form validation
occured. The reason is pretty simple:

The "save as new" button is only shown on "change_view" pages (which makes
sense), see
https://github.com/django/django/blob/master/django/contrib/admin/templatetags/admin_modify.py#L32


… however here …
https://github.com/django/django/blob/master/django/contrib/admin/options.py#L1025
… is the "add_view" called when the object is saved, using the "save as
new" button.

--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:4>

Django

unread,
Jun 26, 2013, 8:32:38 AM6/26/13
to django-...@googlegroups.com
#17417: "Save as new" does not work when a ValidationError is raised
--------------------------------+------------------------------------

Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Resolution:

Keywords: save_as unique | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by hirokiky):

* cc: hirokiky@… (added)


Comment:

I added a patch to fix this bug.

It changes to call add_view when the form is valid and "_saveasnew" in
request.POST.
The form is not valid, it operates as same the normal "save" behavior.

The gregmuellegger's test patch can't be used as it is.
What do you say about this behavior?

--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:6>

Django

unread,
May 25, 2015, 1:31:42 PM5/25/15
to django-...@googlegroups.com
#17417: "Save as new" does not work when a ValidationError is raised
--------------------------------+-------------------------------------
Reporter: cauley.chris@… | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: master
Severity: Normal | Resolution: duplicate

Keywords: save_as unique | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => duplicate


Comment:

Duplicate of #23387 which has been fixed in master (1.9) by only showing
the "Save as new" button if it's selected and there are validation errors.

--
Ticket URL: <https://code.djangoproject.com/ticket/17417#comment:7>

Reply all
Reply to author
Forward
0 new messages