summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2017-08-10 13:18:41 +0500
committerTim Graham <timograham@gmail.com>2017-08-10 10:33:05 -0400
commit22ff86ec52bb536ad9d1fa3ee0c9a3d5eb9925c1 (patch)
tree04d86a768a8001990ebd5256a0a3a4148b964c30
parent5cb7619995bd8df2969d4e92984768a4f14af89b (diff)
Refs #28459 -- Made Oracle get_db_converters() return converter for empty strings only when it's needed.
-rw-r--r--django/db/backends/oracle/operations.py28
1 files 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"