#18176: SQL queries for filtering datetime objects use incorrect format for 
years
<1000
-------------------------------+---------------------------------
     Reporter:  rrotaru        |      Owner:  rrotaru
         Type:  Bug            |     Status:  new
    Component:  Uncategorized  |    Version:  1.4
     Severity:  Normal         |   Keywords:  datetime, SQL, year
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+---------------------------------
 Datetime objects with year values <1000 are auto-formatted to 4-digits by
 adding leading
 zeroes (i.e. year 1 becomes 0001). Also, according to the
 [https://docs.djangoproject.com/en/1.4/ref/models/querysets/#year docs],
 the !__year lookup takes a
 four digit year (i.e., again, 0000-9999). However, when attempting to use
 the !__year lookup on
 years <1000, the SQL generated lacks the leading zeroes and as a result,
 no matches are made.

 Example with Poll objects:
 {{{
 >>> poll1 = Poll(question="This",pub_date=datetime.datetime(0001,01,01))
 >>> poll1.save()
 >>> Poll.objects.filter(pub_date__year=0001) #should return our poll1
 []
 }}}
 Also, certain years <1000, such as 0999, or years ending in a 9 with at
 least one leading zero
 generate "invalid token" syntax errors
 {{{
 >>> poll2 = Poll(question="That",pub_date=datetime.datetime(0999,01,01))
 >>> poll2.save()
 >>> Poll.objects.filter(pub_date__year=0999) #should return our poll2
   Poll.objects.filter(pub_date__year=0999)
                                         ^
 SyntaxError: invalid token
 }}}

 Note: This bug occurs when using sqlite3, I have not tried replicating it
 with other databases. \\
 More discussion on this bug:
 https://groups.google.com/forum/?fromgroups#%21topic/django-
 developers/xPIQKbc4tiQ

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18176>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to