Opened 11 years ago

Closed 11 years ago

#21833 closed Bug (fixed)

Use of new Settings.is_overridden() method breaks if settings.configure() is used

Reported by: Carl Meyer Owned by: nobody
Component: Core (Other) Version: dev
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are two ways to set up Django's settings; one is by passing a settings module to the Settings class, and the other is to call django.conf.settings.configure() with keyword arguments.

In d818e0c9b2b88276cc499974f9eee893170bf0a8 (the new checks framework) a new is_overridden method was added to Settings, and in the "check_1_6_compatibility" check, it is called on django.conf.settings. But if settings.configure() was used, django.conf.settings is not wrapping a Settings instance, it is wrapping a UserSettingsHolder instance. And thus the "check_1_6_compatibility" check dies with "AttributeError: 'module' object has no attribute 'is_overridden'".

Change History (4)

comment:1 by Carl Meyer, 11 years ago

Sorry, my description of the problem was incomplete. UserSettingsHolder does have an implementation of is_overridden(); the problem is that it tries to call self.default_settings.is_overridden(), and if settings.configure() was used, self.default_settings is simply the module object django.conf.global_settings, which obviously has no is_overridden method. Thus the error.

comment:2 by Russell Keith-Magee, 11 years ago

First thought at a fix - either:

1) Add a try/except on the attempt to access the is_overridden property in UserSettingsHolder

2) Add an is_overridden method to global_settings.

I'd prefer (1) so we can keep global_setings clean, but I'm open to other suggestions.

comment:3 by Carl Meyer, 11 years ago

Here's my proposed fix: https://github.com/django/django/pull/2188

In addition to fixing this bug and adding tests for is_overridden(), it also changes the semantics of UserSettingsHolder.is_overridden, but I don't think the previous semantics made sense: they ignored any setting that was explicitly set on the UserSettingsHolder, and they considered deletion of a setting to not be an override.

comment:4 by Carl Meyer <carl@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 6070a5d6a6950bdbd93853c4b1636c7eec820b20:

Fixes #21833 -- Fix UserSettingsHolder.is_overridden() and add tests.

Note: See TracTickets for help on using tickets.
Back to Top