django-etcd-settings icon indicating copy to clipboard operation
django-etcd-settings copied to clipboard

etcd_settings.loader.get_overwrites requires django.conf.settings

Open fladi opened this issue 8 years ago • 2 comments

I tried to offload all of my deployment-specific settings in my DJANGO_SETTINGS_MODULE to etcd_settings but I'm not able to do so because the following line causes django.conf.settings to be imported:

from etcd_settings.loader import get_overwrites

In etcd_settings/__init__.py the EtcdSettingsProxy is instantiated the moment my import happens. This in turn tries to get the DJES_* settings. At this moment SECRET_KEY is missing from the settings because it is one of the values I want to fetch through etcd_settings.

So far, my solution has been to set SECRET_KEY to some fake value before importing etcd_settings but I don't think this is the best solution. IMO it would be better to move the instantiation of EtcdSettingsProxy out of the package __init_.py.

fladi avatar Jan 02 '17 07:01 fladi

@fladi, thank you for the report. Yes, there're some restrictions, requiring a workaround, which you mentioned. We're looking into a ways of overcoming them

sergray avatar Jan 04 '17 10:01 sergray

I think lazy evaluation of EtcdSettingsProxys __init__() method should do the trick. Just using a check in its __getattr__ to load Django settings the first time a member is accessed. I'm busy right now, but I think I can come up with a PR in a few days.

fladi avatar Jan 05 '17 19:01 fladi