#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 , 15 years ago
comment:2 by , 15 years ago
milestone: | → 1.2 |
---|---|
Owner: | changed from | to
Triage Stage: | Unreviewed → 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 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
After a bit of svn updating I've narrowed it down a bit, the behavior starts with revision 12098.