diff --git a/rest_framework/settings.py b/rest_framework/settings.py index adf737126d..9679cad592 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -19,6 +19,8 @@ """ from __future__ import unicode_literals +import warnings + from django.conf import settings from django.test.signals import setting_changed from django.utils import six @@ -135,6 +137,12 @@ ) +# List of settings that have been removed +REMOVED_SETTINGS = ( + "PAGINATE_BY", "PAGINATE_BY_PARAM", "MAX_PAGINATE_BY", +) + + def perform_import(val, setting_name): """ If the given setting is a string import notation, @@ -177,7 +185,7 @@ class APISettings(object): """ def __init__(self, user_settings=None, defaults=None, import_strings=None): if user_settings: - self._user_settings = user_settings + self._user_settings = self.__check_user_settings(user_settings) self.defaults = defaults or DEFAULTS self.import_strings = import_strings or IMPORT_STRINGS @@ -206,6 +214,13 @@ def __getattr__(self, attr): setattr(self, attr, val) return val + def __check_user_settings(self, user_settings): + SETTINGS_DOC = "http://www.django-rest-framework.org/api-guide/settings/" + for setting in REMOVED_SETTINGS: + if setting in user_settings: + warnings.warn("The '%s' setting has been removed. Please refer to '%s' for available settings." % (setting, SETTINGS_DOC), DeprecationWarning) + return user_settings + api_settings = APISettings(None, DEFAULTS, IMPORT_STRINGS) diff --git a/tests/test_settings.py b/tests/test_settings.py index cc8d0d51f1..658c619976 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,5 +1,7 @@ from __future__ import unicode_literals +import warnings + from django.test import TestCase from rest_framework.settings import APISettings @@ -18,6 +20,19 @@ def test_import_error_message_maintained(self): with self.assertRaises(ImportError): settings.DEFAULT_RENDERER_CLASSES + def test_warning_raised_on_removed_setting(self): + """ + Make sure user is alerted with an error when a removed setting + is set. + """ + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + APISettings({ + 'MAX_PAGINATE_BY': 100 + }) + self.assertEqual(len(w), 1) + self.assertTrue(issubclass(w[-1].category, DeprecationWarning)) + class TestSettingTypes(TestCase): def test_settings_consistently_coerced_to_list(self):