Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#12553 closed (fixed)

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

Reported by: pragmar Owned by: Honza_Kral
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: UI/UX:

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 Changed 5 years ago by pragmar

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 5 years ago by Honza_Kral

  • milestone set to 1.2
  • Owner changed from nobody to Honza_Kral
  • Triage Stage changed from Unreviewed to Design 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 Changed 5 years ago by jkocherhans

  • Resolution set to fixed
  • Status changed from new to closed

(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 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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