django-dotenv
django-dotenv copied to clipboard
Allow preventing or suppressing UserWarning
We use dotenv on our project/wsgi.py
and project/celery.py
for local development where we do have a .env
. When we deploy to Heroku our logs get polluted with UserWarnings.
Workaround is to do the following:
with warnings.catch_warnings():
warnings.simplefilter('ignore')
dotenv.read_dotenv()
Is this a suggestion how we should suppress it, or how the code might be modified? We get this warning all over the place and it would be great to eliminate it.
@chris-erickson this is a suggestion on how to suppress it in your app. We could provide an option like dotenv.read_dotenv(silent=True)
and skip the warning. Pull requests are welcome.
We had some discussions in PR #23 about ways to prevent the warning:
@merwok A complementary idea would be to use logging instead of warnings. Logging is more appropriate according to https://docs.python.org/2/howto/logging.html#when-to-use-logging and easy to configure. @tgroshon I also like the idea of replacing warnings with logging. Then a user could specify their log level easily in different environments (DEBUG in development or testing, WARNING in production, etc.).
I know this thread has been dead, but we'd like the suppress mode, and as far as I can tell it is not solved.
I'm down with reviewing a PR that uses logging instead of warnings like discussed in #23.
FTR at my company we have written a small lib to abstract various settings systems including dotenv; no warnings! https://github.com/caravancoop/configstore/