Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7155 -- Corrected DateQuerySet to handle nullable fields. Than…

…ks 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
  • Loading branch information...
commit b8f7b39ccc414e56a99111005146b5f2d7f1d5b0 1 parent 87a704c
Russell Keith-Magee authored June 25, 2008
2  django/db/models/query.py
@@ -690,7 +690,7 @@ def _setup_query(self):
690 690
         self.query.select = []
691 691
         self.query.add_date_select(self._field.column, self._kind, self._order)
692 692
         if self._field.null:
693  
-            self.query.add_filter(('%s__isnull' % self._field.name, True))
  693
+            self.query.add_filter(('%s__isnull' % self._field.name, False))
694 694
 
695 695
     def _clone(self, klass=None, setup=False, **kwargs):
696 696
         c = super(DateQuerySet, self)._clone(klass, False, **kwargs)
7  tests/regressiontests/queries/models.py
@@ -45,6 +45,7 @@ def __unicode__(self):
45 45
 class Item(models.Model):
46 46
     name = models.CharField(max_length=10)
47 47
     created = models.DateTimeField()
  48
+    modified = models.DateTimeField(blank=True, null=True)
48 49
     tags = models.ManyToManyField(Tag, blank=True, null=True)
49 50
     creator = models.ForeignKey(Author)
50 51
     note = models.ForeignKey(Note)
@@ -174,7 +175,7 @@ def __unicode__(self):
174 175
 >>> time2 = datetime.datetime(2007, 12, 19, 21, 0, 0)
175 176
 >>> time3 = datetime.datetime(2007, 12, 20, 22, 25, 0)
176 177
 >>> time4 = datetime.datetime(2007, 12, 20, 21, 0, 0)
177  
->>> i1 = Item(name='one', created=time1, creator=a1, note=n3)
  178
+>>> i1 = Item(name='one', created=time1, modified=time1, creator=a1, note=n3)
178 179
 >>> i1.save()
179 180
 >>> i1.tags = [t1, t2]
180 181
 >>> i2 = Item(name='two', created=time2, creator=a2, note=n2)
@@ -627,6 +628,10 @@ def __unicode__(self):
627 628
 >>> Item.objects.dates('created', 'day').extra(select={'a': 1})
628 629
 [datetime.datetime(2007, 12, 19, 0, 0), datetime.datetime(2007, 12, 20, 0, 0)]
629 630
 
  631
+Bug #7155 -- nullable dates
  632
+>>> Item.objects.dates('modified', 'day')
  633
+[datetime.datetime(2007, 12, 19, 0, 0)]
  634
+
630 635
 Test that parallel iterators work.
631 636
 
632 637
 >>> qs = Tag.objects.all()

0 notes on commit b8f7b39

Please sign in to comment.
Something went wrong with that request. Please try again.