mirror of
https://github.com/django/django.git
synced 2025-06-01 17:49:12 +00:00
Refs #34547 -- Removed DatabaseOperations.field_cast_sql() per deprecation timeline.
This commit is contained in:
parent
ba90b76c6e
commit
6b271ef21d
@ -1,7 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import json
|
import json
|
||||||
import warnings
|
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
|
||||||
import sqlparse
|
import sqlparse
|
||||||
@ -10,7 +9,6 @@ from django.conf import settings
|
|||||||
from django.db import NotSupportedError, transaction
|
from django.db import NotSupportedError, transaction
|
||||||
from django.db.models.expressions import Col
|
from django.db.models.expressions import Col
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
|
|
||||||
|
|
||||||
@ -214,23 +212,6 @@ class BaseDatabaseOperations:
|
|||||||
"""
|
"""
|
||||||
return cursor.fetchone()
|
return cursor.fetchone()
|
||||||
|
|
||||||
def field_cast_sql(self, db_type, internal_type):
|
|
||||||
"""
|
|
||||||
Given a column type (e.g. 'BLOB', 'VARCHAR') and an internal type
|
|
||||||
(e.g. 'GenericIPAddressField'), return the SQL to cast it before using
|
|
||||||
it in a WHERE statement. The resulting string should contain a '%s'
|
|
||||||
placeholder for the column being searched against.
|
|
||||||
"""
|
|
||||||
warnings.warn(
|
|
||||||
(
|
|
||||||
"DatabaseOperations.field_cast_sql() is deprecated use "
|
|
||||||
"DatabaseOperations.lookup_cast() instead."
|
|
||||||
),
|
|
||||||
RemovedInDjango60Warning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
return "%s"
|
|
||||||
|
|
||||||
def force_group_by(self):
|
def force_group_by(self):
|
||||||
"""
|
"""
|
||||||
Return a GROUP BY clause to use with a HAVING clause when no grouping
|
Return a GROUP BY clause to use with a HAVING clause when no grouping
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
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, ColPairs, Expression, Func, Value, When
|
from django.db.models.expressions import Case, ColPairs, Expression, Func, Value, When
|
||||||
from django.db.models.fields import (
|
from django.db.models.fields import (
|
||||||
BooleanField,
|
BooleanField,
|
||||||
@ -15,7 +13,6 @@ 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
|
||||||
|
|
||||||
@ -224,22 +221,6 @@ 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()
|
||||||
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
|
||||||
)
|
)
|
||||||
|
@ -260,6 +260,8 @@ to remove usage of these features.
|
|||||||
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form
|
||||||
renderers are removed.
|
renderers are removed.
|
||||||
|
|
||||||
|
* ``BaseDatabaseOperations.field_cast_sql()`` is removed.
|
||||||
|
|
||||||
See :ref:`deprecated-features-5.1` for details on these changes, including how
|
See :ref:`deprecated-features-5.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import decimal
|
import decimal
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
from django.core.management.color import no_style
|
from django.core.management.color import no_style
|
||||||
from django.db import NotSupportedError, connection, transaction
|
from django.db import NotSupportedError, connection, transaction
|
||||||
from django.db.backends.base.operations import BaseDatabaseOperations
|
from django.db.backends.base.operations import BaseDatabaseOperations
|
||||||
from django.db.models import DurationField
|
from django.db.models import DurationField
|
||||||
from django.db.models.expressions import Col
|
from django.db.models.expressions import Col
|
||||||
from django.db.models.lookups import Exact
|
|
||||||
from django.test import (
|
from django.test import (
|
||||||
SimpleTestCase,
|
SimpleTestCase,
|
||||||
TestCase,
|
TestCase,
|
||||||
@ -15,7 +13,6 @@ from django.test import (
|
|||||||
skipIfDBFeature,
|
skipIfDBFeature,
|
||||||
)
|
)
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
|
|
||||||
from ..models import Author, Book
|
from ..models import Author, Book
|
||||||
|
|
||||||
@ -224,25 +221,3 @@ class SqlFlushTests(TransactionTestCase):
|
|||||||
self.assertEqual(author.pk, 1)
|
self.assertEqual(author.pk, 1)
|
||||||
book = Book.objects.create(author=author)
|
book = Book.objects.create(author=author)
|
||||||
self.assertEqual(book.pk, 1)
|
self.assertEqual(book.pk, 1)
|
||||||
|
|
||||||
|
|
||||||
class DeprecationTests(TestCase):
|
|
||||||
def test_field_cast_sql_warning(self):
|
|
||||||
base_ops = BaseDatabaseOperations(connection=connection)
|
|
||||||
msg = (
|
|
||||||
"DatabaseOperations.field_cast_sql() is deprecated use "
|
|
||||||
"DatabaseOperations.lookup_cast() instead."
|
|
||||||
)
|
|
||||||
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
|
|
||||||
base_ops.field_cast_sql("integer", "IntegerField")
|
|
||||||
self.assertEqual(ctx.filename, __file__)
|
|
||||||
|
|
||||||
def test_field_cast_sql_usage_warning(self):
|
|
||||||
compiler = Author.objects.all().query.get_compiler(connection.alias)
|
|
||||||
msg = (
|
|
||||||
"The usage of DatabaseOperations.field_cast_sql() is deprecated. Implement "
|
|
||||||
"DatabaseOperations.lookup_cast() instead."
|
|
||||||
)
|
|
||||||
with mock.patch.object(connection.ops.__class__, "field_cast_sql"):
|
|
||||||
with self.assertRaisesMessage(RemovedInDjango60Warning, msg):
|
|
||||||
Exact("name", "book__author__name").as_sql(compiler, connection)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user