0
0
mirror of https://github.com/django/django.git synced 2024-11-22 11:57:34 +01:00

Fixed #27544 -- Fixed QuerySet.update(dt=F('dt') + timedelta) crash on SQLite.

This commit is contained in:
Andrew Nester 2016-11-29 20:23:44 +03:00 committed by Tim Graham
parent fb3716b156
commit ade52ef71f
3 changed files with 14 additions and 2 deletions

View File

@ -217,7 +217,7 @@ class DatabaseOperations(BaseDatabaseOperations):
if value is not None:
if not isinstance(value, datetime.datetime):
value = parse_datetime(value)
if settings.USE_TZ:
if settings.USE_TZ and not timezone.is_aware(value):
value = timezone.make_aware(value, self.connection.timezone)
return value

View File

@ -19,3 +19,7 @@ Bugfixes
* Made ``Model.delete(keep_parents=True)`` preserve parent reverse
relationships in multi-table inheritance (:ticket:`27407`).
* Fixed a ``QuerySet.update()`` crash on SQLite when updating a
``DateTimeField`` with an ``F()`` expression and a ``timedelta``
(:ticket:`27544`).

View File

@ -14,7 +14,7 @@ from django.contrib.auth.models import User
from django.core import serializers
from django.core.exceptions import ImproperlyConfigured
from django.db import connection, connections
from django.db.models import Max, Min
from django.db.models import F, Max, Min
from django.http import HttpRequest
from django.template import (
Context, RequestContext, Template, TemplateSyntaxError, context_processors,
@ -26,6 +26,7 @@ from django.test import (
from django.test.utils import requires_tz_support
from django.urls import reverse
from django.utils import six, timezone
from django.utils.timezone import timedelta
from .forms import (
EventForm, EventLocalizedForm, EventLocalizedModelForm, EventModelForm,
@ -569,6 +570,13 @@ class NewDatabaseTests(TestCase):
e = MaybeEvent.objects.create()
self.assertIsNone(e.dt)
def test_update_with_timedelta(self):
initial_dt = timezone.now().replace(microsecond=0)
event = Event.objects.create(dt=initial_dt)
Event.objects.update(dt=F('dt') + timedelta(hours=2))
event.refresh_from_db()
self.assertEqual(event.dt, initial_dt + timedelta(hours=2))
@override_settings(TIME_ZONE='Africa/Nairobi', USE_TZ=True)
class ForcedTimeZoneDatabaseTests(TransactionTestCase):