From b8f7b39ccc414e56a99111005146b5f2d7f1d5b0 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Wed, 25 Jun 2008 13:38:06 +0000 Subject: [PATCH] Fixed #7155 -- Corrected DateQuerySet to handle nullable fields. Thanks to fcaprioli@alice.it for the original report and patch, and to Jeremy Dunck for the test case. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7739 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 2 +- tests/regressiontests/queries/models.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 8714cffb7f..d0fae461e9 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -690,7 +690,7 @@ class DateQuerySet(QuerySet): self.query.select = [] self.query.add_date_select(self._field.column, self._kind, self._order) if self._field.null: - self.query.add_filter(('%s__isnull' % self._field.name, True)) + self.query.add_filter(('%s__isnull' % self._field.name, False)) def _clone(self, klass=None, setup=False, **kwargs): c = super(DateQuerySet, self)._clone(klass, False, **kwargs) diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index aa78d6583a..7270c21dac 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -45,6 +45,7 @@ class Author(models.Model): class Item(models.Model): name = models.CharField(max_length=10) created = models.DateTimeField() + modified = models.DateTimeField(blank=True, null=True) tags = models.ManyToManyField(Tag, blank=True, null=True) creator = models.ForeignKey(Author) note = models.ForeignKey(Note) @@ -174,7 +175,7 @@ by 'info'. Helps detect some problems later. >>> time2 = datetime.datetime(2007, 12, 19, 21, 0, 0) >>> time3 = datetime.datetime(2007, 12, 20, 22, 25, 0) >>> time4 = datetime.datetime(2007, 12, 20, 21, 0, 0) ->>> i1 = Item(name='one', created=time1, creator=a1, note=n3) +>>> i1 = Item(name='one', created=time1, modified=time1, creator=a1, note=n3) >>> i1.save() >>> i1.tags = [t1, t2] >>> i2 = Item(name='two', created=time2, creator=a2, note=n2) @@ -627,6 +628,10 @@ Bug #7087 -- dates with extra select columns >>> Item.objects.dates('created', 'day').extra(select={'a': 1}) [datetime.datetime(2007, 12, 19, 0, 0), datetime.datetime(2007, 12, 20, 0, 0)] +Bug #7155 -- nullable dates +>>> Item.objects.dates('modified', 'day') +[datetime.datetime(2007, 12, 19, 0, 0)] + Test that parallel iterators work. >>> qs = Tag.objects.all()