Django

Code

Ticket #6141: fix.diff

File fix.diff, 1.9 kB (added by Doug Van Horn, 1 year ago)

Modifies query.py and the fields module (init.py) to fix the bug.

  • django/db/models/fields/__init__.py

    old new  
    209209 
    210210    def get_db_prep_lookup(self, lookup_type, value): 
    211211        "Returns field's value prepared for database lookup." 
    212         if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'search'): 
     212        if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'year', 'month', 'day', 'search'): 
    213213            return [value] 
    214214        elif lookup_type in ('range', 'in'): 
    215215            return value 
     
    223223            return ["%%%s" % prep_for_like_query(value)] 
    224224        elif lookup_type == 'isnull': 
    225225            return [] 
    226         elif lookup_type == 'year': 
    227             try: 
    228                 value = int(value) 
    229             except ValueError: 
    230                 raise ValueError("The __year lookup type requires an integer argument") 
    231             return ['%s-01-01 00:00:00' % value, '%s-12-31 23:59:59.999999' % value] 
    232226        raise TypeError("Field has invalid lookup: %s" % lookup_type) 
    233227 
    234228    def has_default(self): 
  • django/db/models/query.py

    old new  
    807807            return '%s IN (%s)' % (field_sql, in_string) 
    808808        else: 
    809809            raise EmptyResultSet 
    810     elif lookup_type in ('range', 'year')
     810    elif lookup_type == 'range'
    811811        return '%s BETWEEN %%s AND %%s' % field_sql 
    812     elif lookup_type in ('month', 'day'): 
     812    elif lookup_type in ('year', 'month', 'day'): 
    813813        return "%s = %%s" % connection.ops.date_extract_sql(lookup_type, field_sql) 
    814814    elif lookup_type == 'isnull': 
    815815        return "%s IS %sNULL" % (field_sql, (not value and 'NOT ' or ''))