Refs #28925 -- Simplified CombinedExpression.as_sql() a bit.

This commit is contained in:
Sergey Fedoseev 2020-06-30 06:30:02 +02:00 committed by Mariusz Felisiak
parent ec5aa2161d
commit 9d752dabe3
1 changed files with 10 additions and 10 deletions

View File

@ -442,20 +442,20 @@ class CombinedExpression(SQLiteNumericMixin, Expression):
def as_sql(self, compiler, connection): def as_sql(self, compiler, connection):
try: try:
lhs_output = self.lhs.output_field lhs_type = self.lhs.output_field.get_internal_type()
except FieldError: except FieldError:
lhs_output = None lhs_type = None
try: try:
rhs_output = self.rhs.output_field rhs_type = self.rhs.output_field.get_internal_type()
except FieldError: except FieldError:
rhs_output = None rhs_type = None
if (not connection.features.has_native_duration_field and if (
((lhs_output and lhs_output.get_internal_type() == 'DurationField') or not connection.features.has_native_duration_field and
(rhs_output and rhs_output.get_internal_type() == 'DurationField'))): 'DurationField' in {lhs_type, rhs_type}
):
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 datetime_fields = {'DateField', 'DateTimeField', 'TimeField'}
lhs_output.get_internal_type() in {'DateField', 'DateTimeField', 'TimeField'} and if self.connector == self.SUB and lhs_type in datetime_fields and lhs_type == rhs_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 = []