|
@@ -1,7 +1,9 @@
|
|
import itertools
|
|
import itertools
|
|
import math
|
|
import math
|
|
|
|
+import warnings
|
|
|
|
|
|
from django.core.exceptions import EmptyResultSet, FullResultSet
|
|
from django.core.exceptions import EmptyResultSet, FullResultSet
|
|
|
|
+from django.db.backends.base.operations import BaseDatabaseOperations
|
|
from django.db.models.expressions import Case, Expression, Func, Value, When
|
|
from django.db.models.expressions import Case, Expression, Func, Value, When
|
|
from django.db.models.fields import (
|
|
from django.db.models.fields import (
|
|
BooleanField,
|
|
BooleanField,
|
|
@@ -13,6 +15,7 @@ from django.db.models.fields import (
|
|
)
|
|
)
|
|
from django.db.models.query_utils import RegisterLookupMixin
|
|
from django.db.models.query_utils import RegisterLookupMixin
|
|
from django.utils.datastructures import OrderedSet
|
|
from django.utils.datastructures import OrderedSet
|
|
|
|
+from django.utils.deprecation import RemovedInDjango60Warning
|
|
from django.utils.functional import cached_property
|
|
from django.utils.functional import cached_property
|
|
from django.utils.hashable import make_hashable
|
|
from django.utils.hashable import make_hashable
|
|
|
|
|
|
@@ -217,8 +220,22 @@ class BuiltinLookup(Lookup):
|
|
def process_lhs(self, compiler, connection, lhs=None):
|
|
def process_lhs(self, compiler, connection, lhs=None):
|
|
lhs_sql, params = super().process_lhs(compiler, connection, lhs)
|
|
lhs_sql, params = super().process_lhs(compiler, connection, lhs)
|
|
field_internal_type = self.lhs.output_field.get_internal_type()
|
|
field_internal_type = self.lhs.output_field.get_internal_type()
|
|
- db_type = self.lhs.output_field.db_type(connection=connection)
|
|
|
|
- lhs_sql = connection.ops.field_cast_sql(db_type, field_internal_type) % lhs_sql
|
|
|
|
|
|
+ if (
|
|
|
|
+ hasattr(connection.ops.__class__, "field_cast_sql")
|
|
|
|
+ and connection.ops.__class__.field_cast_sql
|
|
|
|
+ is not BaseDatabaseOperations.field_cast_sql
|
|
|
|
+ ):
|
|
|
|
+ warnings.warn(
|
|
|
|
+ (
|
|
|
|
+ "The usage of DatabaseOperations.field_cast_sql() is deprecated. "
|
|
|
|
+ "Implement DatabaseOperations.lookup_cast() instead."
|
|
|
|
+ ),
|
|
|
|
+ RemovedInDjango60Warning,
|
|
|
|
+ )
|
|
|
|
+ db_type = self.lhs.output_field.db_type(connection=connection)
|
|
|
|
+ lhs_sql = (
|
|
|
|
+ connection.ops.field_cast_sql(db_type, field_internal_type) % lhs_sql
|
|
|
|
+ )
|
|
lhs_sql = (
|
|
lhs_sql = (
|
|
connection.ops.lookup_cast(self.lookup_name, field_internal_type) % lhs_sql
|
|
connection.ops.lookup_cast(self.lookup_name, field_internal_type) % lhs_sql
|
|
)
|
|
)
|