Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#14951 closed (fixed)

Unique_for_[date|month|year] fails when the DateField is empty

Reported by: Ben Spaulding Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3-alpha
Severity: Keywords: blocker, regression
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using the following fields on a model:

slug = models.SlugField(unique_for_date='pubdate')
pubdate = models.DateTimeField(blank=True, null=True)

Leads to the following error when pubdate is left empty and one tries to save the model instance:

Django Version:	1.3 alpha 1
Exception Type:	AttributeError
Exception Value:	'NoneType' object has no attribute 'day'
Exception Location:	/Users/…/django/db/models/base.py in _perform_date_checks, line 744

(It appears that this issue was addressed years ago, but regressions happen. See #2155.)

Attachments (1)

14951.diff (9.1 KB) - added by Ramiro Morales 10 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 10 years ago by Russell Keith-Magee

milestone: 1.3
Triage Stage: UnreviewedAccepted

Regressions *shouldn't* happen -- that's what the test suite is for :-)

Since this is a regression, its a 1.3 blocker.

Changed 10 years ago by Ramiro Morales

Attachment: 14951.diff added

comment:2 Changed 10 years ago by Ramiro Morales

Has patch: set

comment:3 Changed 10 years ago by Russell Keith-Magee

Keywords: blocker regression added

comment:4 Changed 10 years ago by Ramiro Morales

Resolution: fixed
Status: newclosed

(In [15167]) Fixed #14951 -- Made the unique_for_{date,month,year} model field constraints to not fail when the related DateField is empty.

Existing modelforms tests were extended to cover this case and an equivalent set of tests was added for the model functionality.

comment:5 Changed 10 years ago by Ramiro Morales

I forgot to thank benspaulding in the commit message for bringing this regression to our attention.

comment:6 Changed 10 years ago by Ramiro Morales

(In [15182]) [1.2.X] Fixed #14951 -- Made the unique_for_{date,month,year} model field constraints to not fail when the related DateField is empty.

Existing modelforms tests were extended to cover this case and an equivalent set of tests was added for the model functionality.

Backport of [15167] from trunk.

comment:7 Changed 9 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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