summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wobrock <david.wobrock@gmail.com>2022-07-07 12:20:30 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-07-07 12:21:35 +0200
commit57793b47657ace966ce8ce96d801ac0d85e5efc6 (patch)
treeb8449d4979b67466f7f9e0561cba414453332b12
parent6f80050496780e2f8a65e2a4374dd6375c9fbfa5 (diff)
Refs #27236 -- Refactored out DeprecationForHistoricalMigrationMixin.
-rw-r--r--django/db/models/fields/__init__.py35
-rw-r--r--django/utils/deprecation.py39
2 files changed, 43 insertions, 31 deletions
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 5381a3b17f..3757860f20 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -24,6 +24,7 @@ from django.utils.dateparse import (
parse_duration,
parse_time,
)
+from django.utils.deprecation import DeprecationForHistoricalMigrationMixin
from django.utils.duration import duration_microseconds, duration_string
from django.utils.functional import Promise, cached_property
from django.utils.ipv6 import clean_ipv6_address
@@ -111,7 +112,7 @@ def return_None():
@total_ordering
-class Field(RegisterLookupMixin):
+class Field(DeprecationForHistoricalMigrationMixin, RegisterLookupMixin):
"""Base class for all field types"""
# Designates whether empty strings fundamentally are allowed at the
@@ -137,8 +138,7 @@ class Field(RegisterLookupMixin):
"%(date_field_label)s %(lookup_type)s."
),
}
- system_check_deprecated_details = None
- system_check_removed_details = None
+ check_type = "fields"
# Attributes that don't affect a column definition.
# These attributes are ignored when altering the field.
@@ -263,7 +263,7 @@ class Field(RegisterLookupMixin):
*self._check_null_allowed_for_primary_keys(),
*self._check_backend_specific_checks(**kwargs),
*self._check_validators(),
- *self._check_deprecation_details(),
+ *self.check_deprecation_details(),
]
def _check_field_name(self):
@@ -441,33 +441,6 @@ class Field(RegisterLookupMixin):
)
return errors
- def _check_deprecation_details(self):
- if self.system_check_removed_details is not None:
- return [
- checks.Error(
- self.system_check_removed_details.get(
- "msg",
- "%s has been removed except for support in historical "
- "migrations." % self.__class__.__name__,
- ),
- hint=self.system_check_removed_details.get("hint"),
- obj=self,
- id=self.system_check_removed_details.get("id", "fields.EXXX"),
- )
- ]
- elif self.system_check_deprecated_details is not None:
- return [
- checks.Warning(
- self.system_check_deprecated_details.get(
- "msg", "%s has been deprecated." % self.__class__.__name__
- ),
- hint=self.system_check_deprecated_details.get("hint"),
- obj=self,
- id=self.system_check_deprecated_details.get("id", "fields.WXXX"),
- )
- ]
- return []
-
def get_col(self, alias, output_field=None):
if alias == self.model._meta.db_table and (
output_field is None or output_field == self
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
index caed5b25d4..eaef496138 100644
--- a/django/utils/deprecation.py
+++ b/django/utils/deprecation.py
@@ -157,3 +157,42 @@ class MiddlewareMixin:
thread_sensitive=True,
)(request, response)
return response
+
+
+class DeprecationForHistoricalMigrationMixin:
+ system_check_deprecated_details = None
+ system_check_removed_details = None
+ check_type = ""
+
+ def check_deprecation_details(self):
+ from django.core import checks
+
+ if self.system_check_removed_details is not None:
+ return [
+ checks.Error(
+ self.system_check_removed_details.get(
+ "msg",
+ "%s has been removed except for support in historical "
+ "migrations." % self.__class__.__name__,
+ ),
+ hint=self.system_check_removed_details.get("hint"),
+ obj=self,
+ id=self.system_check_removed_details.get(
+ "id", f"{self.check_type}.EXXX"
+ ),
+ )
+ ]
+ elif self.system_check_deprecated_details is not None:
+ return [
+ checks.Warning(
+ self.system_check_deprecated_details.get(
+ "msg", "%s has been deprecated." % self.__class__.__name__
+ ),
+ hint=self.system_check_deprecated_details.get("hint"),
+ obj=self,
+ id=self.system_check_deprecated_details.get(
+ "id", f"{self.check_type}.WXXX"
+ ),
+ )
+ ]
+ return []