Opened 13 years ago

Closed 13 years ago

Last modified 13 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 13 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Russell Keith-Magee, 13 years ago

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.

by Ramiro Morales, 13 years ago

Attachment: 14951.diff added

comment:2 by Ramiro Morales, 13 years ago

Has patch: set

comment:3 by Russell Keith-Magee, 13 years ago

Keywords: blocker regression added

comment:4 by Ramiro Morales, 13 years ago

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 by Ramiro Morales, 13 years ago

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

comment:6 by Ramiro Morales, 13 years ago

(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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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