From 0d7ba0ff8bb157f6646c1836cc1c658171e7674c Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Sun, 13 Jan 2019 21:58:09 +0000 Subject: [PATCH] Simplified overriding source expressions in some database functions. --- django/db/models/functions/comparison.py | 10 +++------- django/db/models/functions/text.py | 5 ++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/django/db/models/functions/comparison.py b/django/db/models/functions/comparison.py index 6c0b33bdcc..24c3c4b4b8 100644 --- a/django/db/models/functions/comparison.py +++ b/django/db/models/functions/comparison.py @@ -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) diff --git a/django/db/models/functions/text.py b/django/db/models/functions/text.py index 9624f0911f..6216cbf6e6 100644 --- a/django/db/models/functions/text.py +++ b/django/db/models/functions/text.py @@ -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