Django

Code

Changeset 9466

Show
Ignore:
Timestamp:
11/16/08 02:48:24 (2 months ago)
Author:
mtredinnick
Message:

Fixed #3501 -- Fixed date filtering in querysets for nullable date fields. Only
affects SQLite.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/sqlite3/base.py

    r9060 r9466  
    102102 
    103103class DatabaseWrapper(BaseDatabaseWrapper): 
    104      
     104 
    105105    # SQLite requires LIKE statements to include an ESCAPE clause if the value 
    106106    # being escaped has a percent or underscore in it. 
     
    125125    def __init__(self, *args, **kwargs): 
    126126        super(DatabaseWrapper, self).__init__(*args, **kwargs) 
    127          
     127 
    128128        self.features = DatabaseFeatures() 
    129129        self.ops = DatabaseOperations() 
     
    180180 
    181181def _sqlite_extract(lookup_type, dt): 
     182    if dt is None: 
     183        return None 
    182184    try: 
    183185        dt = util.typecast_timestamp(dt) 
  • django/trunk/tests/regressiontests/model_regress/models.py

    r8782 r9466  
    2828 
    2929class Party(models.Model): 
    30     when = models.DateField(
     30    when = models.DateField(null=True
    3131 
    3232class Event(models.Model): 
     
    9494[datetime.date(1998, 12, 31)] 
    9595 
     96# Date filtering was failing with NULL date values in SQLite (regression test 
     97# for #3501, amongst other things). 
     98>>> _ = Party.objects.create() 
     99>>> p = Party.objects.filter(when__month=1)[0] 
     100>>> p.when 
     101datetime.date(1999, 1, 1) 
     102>>> l = Party.objects.filter(pk=p.pk).dates("when", "month") 
     103>>> l[0].month == 1 
     104True 
     105 
    96106# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash when we 
    97107# have usecs values stored on the database