From cd5bb1ea4a459509a45efdd600c737c284e35e43 Mon Sep 17 00:00:00 2001 From: Ben Cail Date: Thu, 15 Feb 2024 15:54:12 -0500 Subject: [PATCH] deprecation warnings for the global settings --- django/conf/__init__.py | 26 ++++++++++++++++++++++++++ tests/model_indexes/tests.py | 13 +++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 5568d7cc83..1c9e83036a 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -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): diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py index 0c8378f624..7253544660 100644 --- a/tests/model_indexes/tests.py +++ b/tests/model_indexes/tests.py @@ -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(