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

Abierto
#179 4 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
359
Forks
86
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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>
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.