Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#14951 closed (fixed)

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

Reported by: benspaulding 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: UI/UX:

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 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by russellm

  • milestone set to 1.3
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

Since this is a regression, its a 1.3 blocker.

Changed 5 years ago by ramiro

comment:2 Changed 5 years ago by ramiro

  • Has patch set

comment:3 Changed 5 years ago by russellm

  • Keywords blocker regression added

comment:4 Changed 5 years ago by ramiro

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

(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 5 years ago by ramiro

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

comment:6 Changed 5 years ago by ramiro

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

  • milestone 1.3 deleted

Milestone 1.3 deleted

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