-
-
Notifications
You must be signed in to change notification settings - Fork 288
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
DATABASES setting for Django not being set #89
Comments
Looks like Django is accessing Load dynaconf explicitly in after this line. or calling it on |
I want to add an implementation targetting Python 3.7 using this https://www.python.org/dev/peps/pep-0562/ and also I am going to try other solutions. If we figureout that the proper way is calling dynaconf on |
Thank you! I was able to follow your advice here[0]. |
Solution: load dynaconf in manage.py, wsgi.py, worker.py, and entry_points.py This patch introduces a workaround for a dynaconf issue[0]. This patch also changes how Pulp is deployed on Travis. A non-default name is used for the database. That way we will know if the settings in the settings file are being used. [0] dynaconf/dynaconf#89 closes: #4046 https://pulp.plan.io/issues/4046
Solution: load dynaconf in manage.py, wsgi.py, worker.py, and entry_points.py This patch introduces a workaround for a dynaconf issue[0]. This patch also changes how Pulp is deployed on Travis. A non-default name is used for the database. That way we will know if the settings in the settings file are being used. [0] dynaconf/dynaconf#89 closes: #4046 https://pulp.plan.io/issues/4046
I did an extensive dive in to Django source code today, The case is that Django is creating the database connection before it loads the Django is doing that because there is a console hint saying This is part of https://docs.djangoproject.com/en/1.11/ref/checks/#database The only setting that Django is looking before One of the possible solution is introducing a new environment variable for Django so users will always need to export the following 2 variables to enable Dynaconf: export DJANGO_SETTINGS_MODULE=dynaconf.contrib.django_settings
export SETTINGS_MODULE_FOR_DYNACONF=myprogram.app.settings Then internally the I want to hear more opinions about this idea ^. For now I will:
|
Any progress on this problem?
I haven't tried the dual environment variable export yet. Are you saying this works out of the box already this way, or that it would need more code changes in dynaconf to make this work? E.g. That said I am on Python 3.7. What does the |
@mspinelli the proposed solution is not implemented yet, it needs to be implemented. Right now to use django there are 2 solutions
|
This changes the configuration engine from everett to dynaconf. dynaconf allows loading configuration from files (json, ini, yaml, toml) as well as environment variables prefixed by ARA_. Our usage of dynaconf is similar to the use case from the Pulp [1] project and they have documented an issue when loading database parameters [2]. This issue is worked around by importing dynaconf in the different entry points. This introduces some other changes as well: - We're now creating a default configuration and data directory at ~/.ara. The location of this directory is controlled with the ARA_BASE_DIR environment variable. - We're now creating a default configuration template in ~/.ara/default_config.yaml. - The default database is now located at ~/.ara/ara.sqlite. The location of this database can be customized with the ARA_DATABASE_NAME environment variable. Note that ARA 0.x used "~/.ara/ansible.sqlite" -- the file name change is deliberate in order to avoid user databases clashing between versions. More documentation on this will be available in an upcoming patch. [1]: https://github.com/pulp/pulp [2]: dynaconf/dynaconf#89 Change-Id: I8178b4ca9f2b4d7f4c45c296c08391e84e8b990d
Hi o/ By the way, I think @apollo13 had a good idea by getting dynaconf to load settings from within settings instead of patching entrypoints for this issue. You can see the commit here: recordsansible/ara-server@fdcc003 |
@rochacbruno Against what? My changes just use dynaconf directly and drop the Django integration. There is not really anything to patch with that regard in dynaconf itself… |
I've found two more Django corner-cases. |
The template problem must e resolved with the recommendation to use The other problems there is a way to fix using getattr but only for python 3.7+ |
IN progress on #126 |
2.0.0 released DATABASE stuff is now fixed. @jasisz can you please test the render template? or add a reproducer on the https://github.com/rochacbruno/dynaconf/tree/master/example/django_example Thanks! |
dynaconf is properly showing the settings I put into /etc/pulp/settings.py
However, django is not using the setting. It seems like Django is loading the settings for the database before dynaconf is loaded.
The text was updated successfully, but these errors were encountered: