mirror of
https://github.com/django/django.git
synced 2025-07-22 18:49:25 +00:00
[1.10.x] Fixed #27828 -- Fixed a crash when subtracting Integer/DurationField from DateField on Oracle/PostgreSQL.
Thanks Mariusz Felisiak for the Oracle workaround. Backport of d5088f838d837fc9e3109c828f18511055f20bea from master
This commit is contained in:
parent
4d9143d029
commit
75327b88a8
@ -382,7 +382,7 @@ class CombinedExpression(Expression):
|
|||||||
return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
|
return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
|
||||||
if (lhs_output and rhs_output and self.connector == self.SUB and
|
if (lhs_output and rhs_output and self.connector == self.SUB and
|
||||||
lhs_output.get_internal_type() in {'DateField', 'DateTimeField', 'TimeField'} and
|
lhs_output.get_internal_type() in {'DateField', 'DateTimeField', 'TimeField'} and
|
||||||
lhs_output.get_internal_type() == lhs_output.get_internal_type()):
|
lhs_output.get_internal_type() == rhs_output.get_internal_type()):
|
||||||
return TemporalSubtraction(self.lhs, self.rhs).as_sql(compiler, connection)
|
return TemporalSubtraction(self.lhs, self.rhs).as_sql(compiler, connection)
|
||||||
expressions = []
|
expressions = []
|
||||||
expression_params = []
|
expression_params = []
|
||||||
|
@ -14,3 +14,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed ``RequestDataTooBig`` and ``TooManyFieldsSent`` exceptions crashing
|
* Fixed ``RequestDataTooBig`` and ``TooManyFieldsSent`` exceptions crashing
|
||||||
rather than generating a bad request response (:ticket:`27820`).
|
rather than generating a bad request response (:ticket:`27820`).
|
||||||
|
|
||||||
|
* Fixed a crash on Oracle and PostgreSQL when subtracting ``DurationField``
|
||||||
|
or ``IntegerField`` from ``DateField`` (:ticket:`27828`).
|
||||||
|
@ -15,7 +15,7 @@ from django.db.models.expressions import (
|
|||||||
When,
|
When,
|
||||||
)
|
)
|
||||||
from django.db.models.functions import (
|
from django.db.models.functions import (
|
||||||
Coalesce, Concat, Length, Lower, Substr, Upper,
|
Cast, Coalesce, Concat, Length, Lower, Substr, Upper,
|
||||||
)
|
)
|
||||||
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
|
||||||
from django.test.utils import Approximate
|
from django.test.utils import Approximate
|
||||||
@ -908,6 +908,15 @@ class FTimeDeltaTests(TestCase):
|
|||||||
).order_by('name')
|
).order_by('name')
|
||||||
self.assertQuerysetEqual(over_estimate, ['e3', 'e4'], lambda e: e.name)
|
self.assertQuerysetEqual(over_estimate, ['e3', 'e4'], lambda e: e.name)
|
||||||
|
|
||||||
|
def test_date_minus_duration(self):
|
||||||
|
value = (
|
||||||
|
Cast(Value(datetime.timedelta(days=4)), models.DurationField())
|
||||||
|
if connection.vendor == 'oracle'
|
||||||
|
else Value(datetime.timedelta(days=4), output_field=models.DurationField())
|
||||||
|
)
|
||||||
|
more_than_4_days = Experiment.objects.filter(assigned__lt=F('completed') - value)
|
||||||
|
self.assertQuerysetEqual(more_than_4_days, ['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