[1.8.x] Fixed #24486 -- Fixed error with datetime and DurationField arithmetic
Backport of ff2aa4019259947734c4791d6afc9f5405d901d0 from master
This commit is contained in:
parent
e150bbd4d6
commit
34e09e532d
@ -398,9 +398,10 @@ class DurationExpression(Expression):
|
|||||||
output = side.output_field
|
output = side.output_field
|
||||||
except FieldError:
|
except FieldError:
|
||||||
pass
|
pass
|
||||||
if output.get_internal_type() == 'DurationField':
|
else:
|
||||||
sql, params = compiler.compile(side)
|
if output.get_internal_type() == 'DurationField':
|
||||||
return connection.ops.format_for_duration_arithmetic(sql), params
|
sql, params = compiler.compile(side)
|
||||||
|
return connection.ops.format_for_duration_arithmetic(sql), params
|
||||||
return compiler.compile(side)
|
return compiler.compile(side)
|
||||||
|
|
||||||
def as_sql(self, compiler, connection):
|
def as_sql(self, compiler, connection):
|
||||||
|
@ -617,8 +617,8 @@ class ExpressionOperatorTests(TestCase):
|
|||||||
class FTimeDeltaTests(TestCase):
|
class FTimeDeltaTests(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
sday = datetime.date(2010, 6, 25)
|
self.sday = sday = datetime.date(2010, 6, 25)
|
||||||
stime = datetime.datetime(2010, 6, 25, 12, 15, 30, 747000)
|
self.stime = stime = datetime.datetime(2010, 6, 25, 12, 15, 30, 747000)
|
||||||
midnight = datetime.time(0)
|
midnight = datetime.time(0)
|
||||||
|
|
||||||
delta0 = datetime.timedelta(0)
|
delta0 = datetime.timedelta(0)
|
||||||
@ -821,6 +821,15 @@ class FTimeDeltaTests(TestCase):
|
|||||||
Experiment.objects.filter(estimated_time__lt=F('end') - F('start'))]
|
Experiment.objects.filter(estimated_time__lt=F('end') - F('start'))]
|
||||||
self.assertEqual(over_estimate, ['e4'])
|
self.assertEqual(over_estimate, ['e4'])
|
||||||
|
|
||||||
|
def test_duration_with_datetime(self):
|
||||||
|
# Exclude e1 which has very high precision so we can test this on all
|
||||||
|
# backends regardless of whether or not it supports
|
||||||
|
# microsecond_precision.
|
||||||
|
over_estimate = Experiment.objects.exclude(name='e1').filter(
|
||||||
|
completed__gt=self.stime + F('estimated_time'),
|
||||||
|
).order_by('name')
|
||||||
|
self.assertQuerysetEqual(over_estimate, ['e3', 'e4'], lambda e: e.name)
|
||||||
|
|
||||||
|
|
||||||
class ValueTests(TestCase):
|
class ValueTests(TestCase):
|
||||||
def test_update_TimeField_using_Value(self):
|
def test_update_TimeField_using_Value(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user