Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#12553 closed (fixed)

unexpected admin behavior for field when submitting "blank" and altering in model.save()

Reported by: pragmar Owned by: Honza Král
Component: contrib.admin Version: 1.2-alpha
Severity: Keywords: model, save, blank, not null
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Today updated from trunk revision 12007 to 1.2 alpha (r12114) and discovered an oddity in the admin - the behavior disappeared after reverting back to 12007 with no other changes applied.

Here's the basic setup:

There's a model with a DateTimeField named "publish" and blank set to True. I've implemented without auto_now_add, but the intended behavior is similar as there's a save method that looks to populate if it is submitted blank. To lend some perspective, the reason it is set up in this manner is to allow a simple admin ui (it's tucked into an advanced collapsible) while maintaining the potential to publish to the future.

class Post(KeenerBase):
    publish = models.DateTimeField('publish',blank=True)
    ...
    def save(self, *args, **kwargs):
        if not self.publish:
            self.publish = datetime.datetime.utcnow()
        super(Post, self).save(*args, **kwargs)

Under 12007 a blank publish field falls through to the Post.save(), adds the datetime and validates. Under 1.2 alpha it does not validate and doesn't appear to hit the save method. The admin validation states the field can not be null. The release notes didn't mention anything regarding model changes to that effect, so I beleive I may've hit a bug.

Change History (4)

comment:1 by pragmar, 15 years ago

After a bit of svn updating I've narrowed it down a bit, the behavior starts with revision 12098.

comment:2 by Honza Král, 15 years ago

milestone: 1.2
Owner: changed from nobody to Honza Král
Triage Stage: UnreviewedDesign decision needed

This is caused by model-validation. The field is specified as null=False, so the validation checks for that. This might be an issue for more people so I am marking it as Design decision needed.

comment:3 by jkocherhans, 15 years ago

Resolution: fixed
Status: newclosed

(In [12206]) Fixed #12512. Changed ModelForm to stop performing model validation on fields that are not part of the form. Thanks, Honza Kral and Ivan Sagalaev.
This reverts some admin and test changes from [12098] and also fixes #12507, #12520, #12552 and #12553.

comment:11 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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