Simplified overriding source expressions in some database functions.

This commit is contained in:
Nick Pope 2019-01-13 21:58:09 +00:00 committed by Tim Graham
parent b86bb47818
commit 0d7ba0ff8b
2 changed files with 5 additions and 10 deletions

View File

@ -53,14 +53,10 @@ class Coalesce(Func):
# Oracle prohibits mixing TextField (NCLOB) and CharField (NVARCHAR2),
# so convert all fields to NCLOB when that type is expected.
if self.output_field.get_internal_type() == 'TextField':
class ToNCLOB(Func):
function = 'TO_NCLOB'
expressions = [
ToNCLOB(expression) for expression in self.get_source_expressions()
]
clone = self.copy()
clone.set_source_expressions(expressions)
clone.set_source_expressions([
Func(expression, function='TO_NCLOB') for expression in self.get_source_expressions()
])
return super(Coalesce, clone).as_sql(compiler, connection, **extra_context)
return self.as_sql(compiler, connection, **extra_context)

View File

@ -67,10 +67,9 @@ class ConcatPair(Func):
def coalesce(self):
# null on either side results in null for expression, wrap with coalesce
c = self.copy()
expressions = [
c.set_source_expressions([
Coalesce(expression, Value('')) for expression in c.get_source_expressions()
]
c.set_source_expressions(expressions)
])
return c