Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning. #1919

Closed
wants to merge 1 commit into from

2 participants

Loic Bistuer Baptiste Mispelon
Loic Bistuer
Owner

Thanks Enrique Martínez for the report and @bmispelon for the tests.

Loic Bistuer loic Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning.
Thanks Enrique Martínez for the report and @bmispelon for the tests.
e0a9f2a
Baptiste Mispelon
Owner

Merged in 17ed99f.

Thanks.

Chris Wilson qris referenced this pull request from a commit in aptivate/django
Chris Wilson qris Fixed #1919 -- filter truncatewords destroys white space
Used @arien's patch and @SmileyChris' comments, integrated with current
code, hopefully made even more efficient for long strings by not
splitting and rejoining them.

https://code.djangoproject.com/ticket/1919
d637d5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Nov 14, 2013
Loic Bistuer loic Fixed #21432 -- DateTimeQuery now copies tzinfo when cloning.
Thanks Enrique Martínez for the report and @bmispelon for the tests.
e0a9f2a
This page is out of date. Refresh to see the latest.
5 django/db/models/sql/subqueries.py
@@ -260,6 +260,11 @@ class DateTimeQuery(DateQuery):
260 260
261 261 compiler = 'SQLDateTimeCompiler'
262 262
  263 + def clone(self, klass=None, memo=None, **kwargs):
  264 + if 'tzinfo' not in kwargs and hasattr(self, 'tzinfo'):
  265 + kwargs['tzinfo'] = self.tzinfo
  266 + return super(DateTimeQuery, self).clone(klass, memo, **kwargs)
  267 +
263 268 def _check_field(self, field):
264 269 assert isinstance(field, DateTimeField), \
265 270 "%r isn't a DateTimeField." % field.name
18 tests/datetimes/tests.py
... ... @@ -1,8 +1,16 @@
1 1 from __future__ import unicode_literals
2 2
3 3 import datetime
  4 +from unittest import skipIf
  5 +
  6 +try:
  7 + import pytz
  8 +except ImportError:
  9 + pytz = None
  10 +
  11 +from django.test import TestCase, override_settings
  12 +from django.utils import timezone
4 13
5   -from django.test import TestCase
6 14
7 15 from .models import Article, Comment, Category
8 16
@@ -81,3 +89,11 @@ def test_related_model_traverse(self):
81 89 ],
82 90 lambda d: d,
83 91 )
  92 +
  93 + @skipIf(pytz is None, "this test requires pytz")
  94 + @override_settings(USE_TZ=True)
  95 + def test_21432(self):
  96 + now = timezone.localtime(timezone.now().replace(microsecond=0))
  97 + Article.objects.create(title="First one", pub_date=now)
  98 + qs = Article.objects.datetimes('pub_date', 'second')
  99 + self.assertEqual(qs[0], now)

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.