Hi all, I'm leading a small group of CS majors in a software development forum focused on learning (and hopefully contributing to) Django at Wesleyan University.
While getting started with the Django Tutorial we noticed some odd behavior that seems to be a bug. If the case, we'd love to be the ones to help out and create a patch. The issue is the following: Filtering using the QuerySet API seems to build incorrect SQL statements for early dates such as year 1. An example from the Django Tutorial: from polls.models import Polls import datetime >>> q = Poll(question="What's up?", pub_date=datetime.datetime.now()) >>> p = Poll(question="Will this work?", pub_date=datetime.datetime(1,1,1,1,1)) >>> p.save() >>> q.save() >>> Poll.objects.filter(pub_date__year=2012) # We should get the poll q (and we do) [<Poll: What's up>] >>> Poll.objects.filter(pub_date__year=1) #We should get the poll p (but we don't) [] This seems to be the case for all dates with a non 4 digit year (999, also has some problem). The SQL queries that are being generated are (for sqlite): {'sql': u'INSERT INTO "polls_poll" ("question", "pub_date") VALUES (Year is 999, 0999-09-09 00 <+33999090900>:00:00)', 'time': '0.043'}, {'sql': u'SELECT "polls_poll"."id", "polls_poll"."question", "polls_poll"."pub_date" FROM "polls_poll" WHERE "polls_poll"."pub_date" BETWEEN 999-01-01 and 999-12-31 23:59:59.999999 LIMIT 21', 'time': '0.000'}] So it seems like there is a normalization process of converting all years into a 4 digit integer when creating objects, but when searching or filtering for objects the years the SQL isn't correct. I'd think the correct SQL statement should simply have the year dates have 4 digits like the SQL statement which works: sqlite> SELECT "polls_poll"."id", "polls_poll"."question", "polls_poll"."pub_date" FROM "polls_poll" WHERE "polls_poll"."pub_date" BETWEEN "0999-01-01" and "0999-12-31 23 <+33999123123>:59:59.999999"; 5|Year is 999|0999-09-09 00 <+33999090900>:00:00 If this is, in fact, a bug and not intentional we'd love to be the ones to create tests and a patch. Cheers, Evan -- You received this message because you are subscribed to the Google Groups "Django developers" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-developers/-/I95Mmv38wyUJ. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.