agateblue / agateblue/django-dynamic-preferences

if a preference is imported into a module that is imported via apps.AppConfig.ready, any new entries in the registry are not being saved to the database and, of course, the server will fail on startup

未關閉
#179 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
359
分支
86
PR 合併指標
30 天內沒有已合併 PR

描述

I have a large project with multiple apps and a dynamic registry defined in one of the apps. I haven't had any problems with accessing preferences until this following scenario happened.

In an app I am importing a signals module (as recommended) in the app config module and one of the imports from signals module references a preference in the registry.
Unfortunately, any changes to the preferences table after this code change is introduced are not being applied. In order to make any further changes to the preferences registry after this code change, I need to add/update the changes to the dynamicpreferences table manually.
Moving the app with the offending import before the app where the registry is defined in INSTALLED_APPS doesn't fix the problem.

This is what happens around the offending import:

```
^C(phsa_venv) phsa@lvmsocq01:~/p_soc_auto$ python manage.py runserver 0.0.0.0:8091
> /opt/phsa/p_soc_auto/mail_collector/signals.py(30)()
29 ipdb.set_trace()
---> 30 from .tasks import dispatch_data
31 from p_soc_auto_base.utils import get_subscription

ipdb> n
/opt/phsa/.envs/phsa_venv/lib/python3.6/site-packages/dynamic_preferences/registries.py:136: UserWarning: Creating a fallback preference with section "exchange" and name "expire_bagus".This means you have preferences in your database that don't match any registered preference. If you want to delete these entries, please refer to the documentation: https://django-dynamic-preferences.readthedocs.io/en/latest/lifecycle.html
warnings.warn(message.format(section_name, pref_name))
/opt/phsa/.envs/phsa_venv/lib/python3.6/site-packages/dynamic_preferences/registries.py:136: UserWarning: Creating a fallback preference with section "exchange" and name "expire_bogus".This means you have preferences in your database that don't match any registered preference. If you want to delete these entries, please refer to the documentation: https://django-dynamic-preferences.readthedocs.io/en/latest/lifecycle.html
warnings.warn(message.format(section_name, pref_name))
KeyError:
> /opt/phsa/p_soc_auto/mail_collector/signals.py(30)()
29 ipdb.set_trace()
---> 30 from .tasks import dispatch_data
31 from p_soc_auto_base.utils import get_subscription

ipdb> n
--Return--
None
> /opt/phsa/p_soc_auto/mail_collector/signals.py(30)()
29 ipdb.set_trace()
---> 30 from .tasks import dispatch_data
31 from p_soc_auto_base.utils import get_subscription

ipdb> n
KeyError:
> (219)_call_with_frames_removed()

ipdb>
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。