1
0
mirror of https://github.com/django/django.git synced 2025-04-04 21:46:40 +00:00

deprecation warnings for the global settings

This commit is contained in:
Ben Cail 2024-02-15 15:54:12 -05:00
parent 5d5a4ce44b
commit cd5bb1ea4a
2 changed files with 37 additions and 2 deletions

View File

@ -27,6 +27,10 @@ STATICFILES_STORAGE_ALIAS = "staticfiles"
FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG = (
"The FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated."
)
DEFAULT_TABLESPACE_DEPRECATED_MSG = "The DEFAULT_TABLESPACE setting is deprecated."
DEFAULT_INDEX_TABLESPACE_DEPRECATED_MSG = (
"The DEFAULT_INDEX_TABLESPACE setting is deprecated."
)
class SettingsReference(str):
@ -192,6 +196,18 @@ class Settings:
RemovedInDjango60Warning,
)
if self.is_overridden("DEFAULT_TABLESPACE"):
warnings.warn(
DEFAULT_TABLESPACE_DEPRECATED_MSG,
RemovedInDjango60Warning,
)
if self.is_overridden("DEFAULT_INDEX_TABLESPACE"):
warnings.warn(
DEFAULT_INDEX_TABLESPACE_DEPRECATED_MSG,
RemovedInDjango60Warning,
)
if hasattr(time, "tzset") and self.TIME_ZONE:
# When we can, attempt to validate the timezone. If we can't find
# this file, no check happens and it's harmless.
@ -241,6 +257,16 @@ class UserSettingsHolder:
FORMS_URLFIELD_ASSUME_HTTPS_DEPRECATED_MSG,
RemovedInDjango60Warning,
)
if name == "DEFAULT_TABLESPACE":
warnings.warn(
DEFAULT_TABLESPACE_DEPRECATED_MSG,
RemovedInDjango60Warning,
)
if name == "DEFAULT_INDEX_TABLESPACE":
warnings.warn(
DEFAULT_INDEX_TABLESPACE_DEPRECATED_MSG,
RemovedInDjango60Warning,
)
super().__setattr__(name, value)
def __delattr__(self, name):

View File

@ -3,8 +3,15 @@ from unittest import mock
from django.conf import settings
from django.db import connection, models
from django.db.models.functions import Lower, Upper
from django.test import SimpleTestCase, TestCase, override_settings, skipUnlessDBFeature
from django.test import (
SimpleTestCase,
TestCase,
ignore_warnings,
override_settings,
skipUnlessDBFeature,
)
from django.test.utils import isolate_apps
from django.utils.deprecation import RemovedInDjango60Warning
from .models import Book, ChildModel1, ChildModel2
@ -305,9 +312,10 @@ class SimpleIndexesTests(SimpleTestCase):
)
@override_settings(DEFAULT_TABLESPACE=None)
@ignore_warnings(category=RemovedInDjango60Warning)
class IndexesTests(TestCase):
@skipUnlessDBFeature("supports_tablespaces")
@override_settings(DEFAULT_TABLESPACE=None)
def test_db_tablespace(self):
editor = connection.schema_editor()
# Index with db_tablespace attribute.
@ -346,6 +354,7 @@ class IndexesTests(TestCase):
self.assertIn('"idx_tbls"', str(index.create_sql(Book, editor)).lower())
@skipUnlessDBFeature("supports_tablespaces")
@override_settings(DEFAULT_TABLESPACE=None)
def test_func_with_tablespace(self):
# Functional index with db_tablespace attribute.
index = models.Index(