From 22ff86ec52bb536ad9d1fa3ee0c9a3d5eb9925c1 Mon Sep 17 00:00:00 2001
From: Sergey Fedoseev <fedoseev.sergey@gmail.com>
Date: Thu, 10 Aug 2017 13:18:41 +0500
Subject: [PATCH] Refs #28459 -- Made Oracle get_db_converters() return
 converter for empty strings only when it's needed.

---
 django/db/backends/oracle/operations.py | 28 ++++++++++++++-----------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/django/db/backends/oracle/operations.py b/django/db/backends/oracle/operations.py
index 60fce427d7..fb1b1a21a0 100644
--- a/django/db/backends/oracle/operations.py
+++ b/django/db/backends/oracle/operations.py
@@ -165,7 +165,15 @@ END;
             converters.append(self.convert_timefield_value)
         elif internal_type == 'UUIDField':
             converters.append(self.convert_uuidfield_value)
-        converters.append(self.convert_empty_values)
+        # Oracle stores empty strings as null. If the field accepts the empty
+        # string, undo this to adhere to the Django convention of using
+        # the empty string instead of null.
+        if expression.field.empty_strings_allowed:
+            converters.append(
+                self.convert_empty_bytes
+                if internal_type == 'BinaryField' else
+                self.convert_empty_string
+            )
         return converters
 
     def convert_textfield_value(self, value, expression, connection):
@@ -208,17 +216,13 @@ END;
             value = uuid.UUID(value)
         return value
 
-    def convert_empty_values(self, value, expression, connection):
-        # Oracle stores empty strings as null. We need to undo this in
-        # order to adhere to the Django convention of using the empty
-        # string instead of null, but only if the field accepts the
-        # empty string.
-        field = expression.output_field
-        if value is None and field.empty_strings_allowed:
-            value = ''
-            if field.get_internal_type() == 'BinaryField':
-                value = b''
-        return value
+    @staticmethod
+    def convert_empty_string(value, expression, connection):
+        return '' if value is None else value
+
+    @staticmethod
+    def convert_empty_bytes(value, expression, connection):
+        return b'' if value is None else value
 
     def deferrable_sql(self):
         return " DEFERRABLE INITIALLY DEFERRED"