Skip to content

Commit

Permalink
Merge pull request #327 from ticosax/fix-deprecated-settings
Browse files Browse the repository at this point in the history
Remove deprecated default fields only from the global
  • Loading branch information
ticosax committed Jan 25, 2022
2 parents bb2523d + 5f43845 commit 861935f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions configurations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def __new__(cls, name, bases, attrs):
if parents:
for base in bases[::-1]:
settings_vars.update(uppercase_attributes(base))
attrs = dict(settings_vars, **attrs)

deprecated_settings = {
# DEFAULT_HASHING_ALGORITHM is always deprecated, as it's a
Expand All @@ -51,11 +50,12 @@ def __new__(cls, name, bases, attrs):
# PASSWORD_RESET_TIMEOUT_DAYS is deprecated in favor of
# PASSWORD_RESET_TIMEOUT in Django 3.1
# https://github.com/django/django/commit/226ebb17290b604ef29e82fb5c1fbac3594ac163#diff-ec2bed07bb264cb95a80f08d71a47c06R163-R170
if "PASSWORD_RESET_TIMEOUT" in attrs:
if "PASSWORD_RESET_TIMEOUT" in settings_vars:
deprecated_settings.add("PASSWORD_RESET_TIMEOUT_DAYS")
for deprecated_setting in deprecated_settings:
if deprecated_setting in attrs:
del attrs[deprecated_setting]
if deprecated_setting in settings_vars:
del settings_vars[deprecated_setting]
attrs = {**settings_vars, **attrs}

return super().__new__(cls, name, bases, attrs)

Expand Down
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Changelog
unreleased
^^^^^^^^^^

- Fix regression where settings receiving a default were ignored. #323 #327

v2.3.1 (2021-11-08)
^^^^^^^^^^^^^^^^^^^

Expand Down
4 changes: 4 additions & 0 deletions tests/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ def pre_setup(cls):
@classmethod
def post_setup(cls):
cls.POST_SETUP_TEST_SETTING = 7


class TestWithDefaultSetExplicitely(Test):
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
6 changes: 6 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def test_global_settings(self):
self.assertEqual(repr(Configuration),
"<Configuration 'configurations.base.Configuration'>")

def test_deprecated_settings_but_set_by_user(self):
from tests.settings.main import TestWithDefaultSetExplicitely
TestWithDefaultSetExplicitely.setup()
self.assertEqual(TestWithDefaultSetExplicitely.DEFAULT_AUTO_FIELD,
"django.db.models.BigAutoField")

def test_repr(self):
from tests.settings.main import Test
self.assertEqual(repr(Test),
Expand Down

0 comments on commit 861935f

Please sign in to comment.