mirror of https://github.com/django/django.git
Refs #28370 -- Removed support for the context arg of Field.from_db_value() and Expression.convert_value().
Per deprecation timeline.
This commit is contained in:
parent
7c66aaa2b6
commit
da5eb3d56c
|
@ -6,7 +6,6 @@ from django.contrib.postgres.validators import ArrayMaxLengthValidator
|
|||
from django.core import checks, exceptions
|
||||
from django.db.models import Field, IntegerField, Transform
|
||||
from django.db.models.lookups import Exact, In
|
||||
from django.utils.inspect import func_supports_parameter
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from ..utils import prefix_validation_error
|
||||
|
@ -112,9 +111,7 @@ class ArrayField(CheckFieldDefaultMixin, Field):
|
|||
if value is None:
|
||||
return value
|
||||
return [
|
||||
self.base_field.from_db_value(item, expression, connection, {})
|
||||
if func_supports_parameter(self.base_field.from_db_value, 'context') # RemovedInDjango30Warning
|
||||
else self.base_field.from_db_value(item, expression, connection)
|
||||
self.base_field.from_db_value(item, expression, connection)
|
||||
for item in value
|
||||
]
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ from django.conf import settings
|
|||
from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache
|
||||
from django.db import DatabaseError, connections, models, router, transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.inspect import func_supports_parameter
|
||||
|
||||
|
||||
class Options:
|
||||
|
@ -85,10 +84,7 @@ class DatabaseCache(BaseDatabaseCache):
|
|||
converters = (connection.ops.get_db_converters(expression) + expression.get_db_converters(connection))
|
||||
for key, value, expires in rows:
|
||||
for converter in converters:
|
||||
if func_supports_parameter(converter, 'context'): # RemovedInDjango30Warning
|
||||
expires = converter(expires, expression, connection, {})
|
||||
else:
|
||||
expires = converter(expires, expression, connection)
|
||||
expires = converter(expires, expression, connection)
|
||||
if expires < timezone.now():
|
||||
expired_keys.append(key)
|
||||
else:
|
||||
|
@ -160,10 +156,7 @@ class DatabaseCache(BaseDatabaseCache):
|
|||
expression = models.Expression(output_field=models.DateTimeField())
|
||||
for converter in (connection.ops.get_db_converters(expression) +
|
||||
expression.get_db_converters(connection)):
|
||||
if func_supports_parameter(converter, 'context'): # RemovedInDjango30Warning
|
||||
current_expires = converter(current_expires, expression, connection, {})
|
||||
else:
|
||||
current_expires = converter(current_expires, expression, connection)
|
||||
current_expires = converter(current_expires, expression, connection)
|
||||
|
||||
exp = connection.ops.adapt_datetimefield_value(exp)
|
||||
if result and mode == 'touch':
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import collections
|
||||
import functools
|
||||
import re
|
||||
import warnings
|
||||
from itertools import chain
|
||||
|
@ -14,10 +13,7 @@ from django.db.models.sql.constants import (
|
|||
from django.db.models.sql.query import Query, get_order_dir
|
||||
from django.db.transaction import TransactionManagementError
|
||||
from django.db.utils import DatabaseError, NotSupportedError
|
||||
from django.utils.deprecation import (
|
||||
RemovedInDjango30Warning, RemovedInDjango31Warning,
|
||||
)
|
||||
from django.utils.inspect import func_supports_parameter
|
||||
from django.utils.deprecation import RemovedInDjango31Warning
|
||||
|
||||
FORCE = object()
|
||||
|
||||
|
@ -1015,20 +1011,7 @@ class SQLCompiler:
|
|||
backend_converters = self.connection.ops.get_db_converters(expression)
|
||||
field_converters = expression.get_db_converters(self.connection)
|
||||
if backend_converters or field_converters:
|
||||
convs = []
|
||||
for conv in (backend_converters + field_converters):
|
||||
if func_supports_parameter(conv, 'context'):
|
||||
warnings.warn(
|
||||
'Remove the context parameter from %s.%s(). Support for it '
|
||||
'will be removed in Django 3.0.' % (
|
||||
conv.__self__.__class__.__name__,
|
||||
conv.__name__,
|
||||
),
|
||||
RemovedInDjango30Warning,
|
||||
)
|
||||
conv = functools.partial(conv, context={})
|
||||
convs.append(conv)
|
||||
converters[i] = (convs, expression)
|
||||
converters[i] = (backend_converters + field_converters, expression)
|
||||
return converters
|
||||
|
||||
def apply_converters(self, rows, converters):
|
||||
|
|
|
@ -244,6 +244,9 @@ to remove usage of these features.
|
|||
|
||||
* ``HttpRequest.xreadlines()`` is removed.
|
||||
|
||||
* Support for the ``context`` argument of ``Field.from_db_value()`` and
|
||||
``Expression.convert_value()`` is removed.
|
||||
|
||||
See :ref:`deprecated-features-2.1` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
|
|
|
@ -28,12 +28,3 @@ class CashModel(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return str(self.cash)
|
||||
|
||||
|
||||
class CashFieldDeprecated(CashField):
|
||||
def from_db_value(self, value, expression, connection, context):
|
||||
return super().from_db_value(value, expression, connection)
|
||||
|
||||
|
||||
class CashModelDeprecated(models.Model):
|
||||
cash = CashFieldDeprecated()
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
from django.test import TestCase
|
||||
from django.utils.deprecation import RemovedInDjango30Warning
|
||||
|
||||
from .models import Cash, CashModelDeprecated
|
||||
|
||||
|
||||
class FromDBValueDeprecationTests(TestCase):
|
||||
|
||||
def test_deprecation(self):
|
||||
msg = (
|
||||
'Remove the context parameter from CashFieldDeprecated.from_db_value(). '
|
||||
'Support for it will be removed in Django 3.0.'
|
||||
)
|
||||
CashModelDeprecated.objects.create(cash='12.50')
|
||||
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
|
||||
instance = CashModelDeprecated.objects.get()
|
||||
self.assertIsInstance(instance.cash, Cash)
|
Loading…
Reference in New Issue