Skip to content

Commit 285378c

Browse files
committed
Remove unused interprets_empty_strings_as_nulls
1 parent d6b8d30 commit 285378c

File tree

9 files changed

+23
-90
lines changed

9 files changed

+23
-90
lines changed

plain-models/plain/models/backends/base/features.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class BaseDatabaseFeatures:
99
empty_fetchmany_value = []
1010
update_can_self_select = True
1111

12-
# Does the backend distinguish between '' and None?
13-
interprets_empty_strings_as_nulls = False
14-
1512
# Does the backend support initially deferrable unique constraints?
1613
supports_deferrable_unique_constraints = False
1714

plain-models/plain/models/backends/base/schema.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,6 @@ def _iter_column_sql(
297297
else:
298298
yield column_default
299299
params.append(default_value)
300-
# Oracle treats the empty string ('') as null, so coerce the null
301-
# option whenever '' is a possible value.
302-
if (
303-
field.empty_strings_allowed
304-
and not field.primary_key
305-
and self.connection.features.interprets_empty_strings_as_nulls
306-
):
307-
null = True
308300

309301
if not null:
310302
yield "NOT NULL"
@@ -1042,27 +1034,20 @@ def _alter_column_null_sql(self, model, old_field, new_field):
10421034
Return a (sql, params) fragment to set a column to null or non-null
10431035
as required by new_field, or None if no changes are required.
10441036
"""
1045-
if (
1046-
self.connection.features.interprets_empty_strings_as_nulls
1047-
and new_field.empty_strings_allowed
1048-
):
1049-
# The field is nullable in the database anyway, leave it alone.
1050-
return
1051-
else:
1052-
new_db_params = new_field.db_parameters(connection=self.connection)
1053-
sql = (
1054-
self.sql_alter_column_null
1055-
if new_field.allow_null
1056-
else self.sql_alter_column_not_null
1057-
)
1058-
return (
1059-
sql
1060-
% {
1061-
"column": self.quote_name(new_field.column),
1062-
"type": new_db_params["type"],
1063-
},
1064-
[],
1065-
)
1037+
new_db_params = new_field.db_parameters(connection=self.connection)
1038+
sql = (
1039+
self.sql_alter_column_null
1040+
if new_field.allow_null
1041+
else self.sql_alter_column_not_null
1042+
)
1043+
return (
1044+
sql
1045+
% {
1046+
"column": self.quote_name(new_field.column),
1047+
"type": new_db_params["type"],
1048+
},
1049+
[],
1050+
)
10661051

10671052
def _alter_column_default_sql(self, model, old_field, new_field, drop=False):
10681053
"""

plain-models/plain/models/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,7 @@ def _perform_unique_checks(self, unique_checks):
833833
f = self._meta.get_field(field_name)
834834
lookup_value = getattr(self, f.attname)
835835
# TODO: Handle multiple backends with different feature flags.
836-
if lookup_value is None or (
837-
lookup_value == ""
838-
and db_connection.features.interprets_empty_strings_as_nulls
839-
):
836+
if lookup_value is None:
840837
# no value, skip the lookup
841838
continue
842839
if f.primary_key and not self._state.adding:

plain-models/plain/models/constraints.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from types import NoneType
33

44
from plain.exceptions import FieldError, ValidationError
5-
from plain.models.db import db_connection
65
from plain.models.expressions import Exists, ExpressionList, F, OrderBy
76
from plain.models.indexes import IndexExpression
87
from plain.models.lookups import Exact
@@ -356,10 +355,7 @@ def validate(self, model, instance, exclude=None):
356355
return
357356
field = model._meta.get_field(field_name)
358357
lookup_value = getattr(instance, field.attname)
359-
if lookup_value is None or (
360-
lookup_value == ""
361-
and db_connection.features.interprets_empty_strings_as_nulls
362-
):
358+
if lookup_value is None:
363359
# A composite constraint containing NULL value cannot cause
364360
# a violation since NULL != NULL in SQL.
365361
return

plain-models/plain/models/fields/__init__.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,7 @@ def _check_db_comment(self, database=False, **kwargs):
365365
return errors
366366

367367
def _check_null_allowed_for_primary_keys(self):
368-
if (
369-
self.primary_key
370-
and self.allow_null
371-
and not db_connection.features.interprets_empty_strings_as_nulls
372-
):
368+
if self.primary_key and self.allow_null:
373369
# We cannot reliably check this for backends like Oracle which
374370
# consider NULL and '' to be equal (and thus set up
375371
# character-based fields a little differently).
@@ -885,11 +881,7 @@ def _get_default(self):
885881
return self.default
886882
return lambda: self.default
887883

888-
if (
889-
not self.empty_strings_allowed
890-
or self.allow_null
891-
and not db_connection.features.interprets_empty_strings_as_nulls
892-
):
884+
if not self.empty_strings_allowed or self.allow_null:
893885
return return_None
894886
return str # return empty string
895887

plain-models/plain/models/fields/related.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -974,11 +974,7 @@ def get_default(self):
974974

975975
def get_db_prep_save(self, value, connection):
976976
if value is None or (
977-
value == ""
978-
and (
979-
not self.target_field.empty_strings_allowed
980-
or connection.features.interprets_empty_strings_as_nulls
981-
)
977+
value == "" and not self.target_field.empty_strings_allowed
982978
):
983979
return None
984980
else:
@@ -1019,8 +1015,6 @@ def convert_empty_strings(self, value, expression, connection):
10191015

10201016
def get_db_converters(self, connection):
10211017
converters = super().get_db_converters(connection)
1022-
if connection.features.interprets_empty_strings_as_nulls:
1023-
converters += [self.convert_empty_strings]
10241018
return converters
10251019

10261020
def get_col(self, alias, output_field=None):

plain-models/plain/models/fields/related_descriptors.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,12 @@ def _apply_rel_filters(self, queryset):
369369
"""
370370
Filter the queryset for the instance this manager is bound to.
371371
"""
372-
empty_strings_as_null = (
373-
db_connection.features.interprets_empty_strings_as_nulls
374-
)
375372
queryset._add_hints(instance=self.instance)
376373
queryset._defer_next_filter = True
377374
queryset = queryset.filter(**self.core_filters)
378375
for field in self.field.foreign_related_fields:
379376
val = getattr(self.instance, field.attname)
380-
if val is None or (val == "" and empty_strings_as_null):
377+
if val is None:
381378
return queryset.none()
382379
if self.field.many_to_one:
383380
# Guard against field-like objects such as GenericRelation

plain-models/plain/models/forms.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,7 @@ def modelfield_to_formfield(
769769
# Passing max_length to forms.CharField means that the value's length
770770
# will be validated twice. This is considered acceptable since we want
771771
# the value in the form field (to pass into widget for example).
772-
# TODO: Handle multiple backends with different feature flags.
773-
from plain.models.db import db_connection
774-
775-
if (
776-
modelfield.allow_null
777-
and not db_connection.features.interprets_empty_strings_as_nulls
778-
):
772+
if modelfield.allow_null:
779773
defaults["empty_value"] = None
780774
return fields.CharField(
781775
max_length=modelfield.max_length,

plain-models/plain/models/sql/query.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,16 +1233,6 @@ def build_lookup(self, lookups, lhs, rhs):
12331233
raise ValueError("Cannot use None as a query value")
12341234
return lhs.get_lookup("isnull")(lhs, True)
12351235

1236-
# For Oracle '' is equivalent to null. The check must be done at this
1237-
# stage because join promotion can't be done in the compiler. A similar
1238-
# thing is done in is_nullable(), too.
1239-
if (
1240-
lookup_name == "exact"
1241-
and lookup.rhs == ""
1242-
and db_connection.features.interprets_empty_strings_as_nulls
1243-
):
1244-
return lhs.get_lookup("isnull")(lhs, True)
1245-
12461236
return lookup
12471237

12481238
def try_transform(self, lhs, name):
@@ -2466,20 +2456,11 @@ def trim_start(self, names_with_path):
24662456
return trimmed_prefix, contains_louter
24672457

24682458
def is_nullable(self, field):
2469-
"""
2470-
Check if the given field should be treated as nullable.
2471-
2472-
Some backends treat '' as null and Plain treats such fields as
2473-
nullable for those backends. In such situations field.allow_null can be
2474-
False even if we should treat the field as nullable.
2475-
"""
2459+
"""Check if the given field should be treated as nullable."""
24762460
# QuerySet does not have knowledge of which connection is going to be
24772461
# used. For the single-database setup we always reference the default
24782462
# connection here.
2479-
return field.allow_null or (
2480-
field.empty_strings_allowed
2481-
and db_connection.features.interprets_empty_strings_as_nulls
2482-
)
2463+
return field.allow_null
24832464

24842465

24852466
def get_order_dir(field, default="ASC"):

0 commit comments

Comments
 (0)