Opened 20 years ago
Closed 20 years ago
#1776 closed defect (fixed)
[patch] DateQuerySet broken when date field allows NULL
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Core (Other) | Version: | dev |
| Severity: | normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
…which also breaks the date_hierarchy feature for such a field.
Patch is trivial:
Index: django/db/models/query.py
===================================================================
--- django/db/models/query.py (revision 393)
+++ django/db/models/query.py (working copy)
@@ -478,7 +478,7 @@
from django.db.backends.util import typecast_timestamp
self._order_by = () # Clear this because it'll mess things up otherwise.
if self._field.null:
- date_query._where.append('%s.%s IS NOT NULL' % \
+ self._where.append('%s.%s IS NOT NULL' % \
(backend.quote_name(self.model._meta.db_table), backend.quote_name(self._field.column)))
select, sql, params = self._get_sql_clause()
sql = 'SELECT %s %s GROUP BY 1 ORDER BY 1 %s' % \
Note:
See TracTickets
for help on using tickets.
(In [2857]) Fixed #1776 -- Fixed bug in DateQuerySet when the field is null. Thanks, Christopher Lenz