-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix loading of local settings. #461
base: master
Are you sure you want to change the base?
Conversation
In drxf/settings.py move importing of local settings last thing that is done, this way any/all custom settings gets priority as they're loaded last. Signed-off-by: Sami Olmari <[email protected]>
In my testing I don't see any difference on where the settings_local is loaded.
and it prints out But what I do see is that Constance has added an object for the setting even if I have never saved anything into it...
Looks like constance initializes its objects when the key is queried for the first time. It will take the default value configured at that point in time and then keeps it in the db. |
That would conceptually match why local settings loading as last thing would make it also go... Does generally things know local settings has priority? Or how else they know other than loading local settings in settings.py as last thing "overriding" anything set prior? Tho goes too deep into code for my knowledge anyways, kinda, sorta. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in order for this to function as I originally intended it we need to load settings from settings_local.py both before setting up constance and afterwards.
If you don't define a constance config in your local settings, you probably want your local settings to be loaded into the defaults that are defined in the constance config section here in settings.py
.
Feels a bit clunky, but that's kinda how it has to be when the constance config reads from settings/settings_local.
I'm not very well versed in python or django, so the ordering may be moot.
# Load non-default settings from settings_local.py if it exists | ||
try: | ||
from .settings_local import * # noqa | ||
except ImportError: | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un-delete these lines and the PR will work as intended. Perhaps leave a comment like so:
settings_local is loaded so that the constance config will receive defaults from settings_local.
|
||
# Load non-default settings from settings_local.py if it exists | ||
try: | ||
from .settings_local import * # noqa | ||
except ImportError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this work?
# Load non-default settings from settings_local.py if it exists | |
try: | |
from .settings_local import * # noqa | |
except ImportError: | |
pass | |
# Load constance config from settings_local.py if it exists | |
try: | |
from .settings_local import CONSTANCE_BACKEND, CONSTANCE_CONFIG # noqa | |
except ImportError: | |
pass |
Just to clarify: Here is the sequence of operations we need:
Local settings should always override, therefore we need to override the constance config in the end, if applicable |
In drxf/settings.py move importing of local settings last thing that is done, this way any/all custom settings gets priority as they're loaded last.
Fixes: #460
Signed-off-by: Sami Olmari [email protected]