django-dotenv icon indicating copy to clipboard operation
django-dotenv copied to clipboard

Allow preventing or suppressing UserWarning

Open jpadilla opened this issue 9 years ago • 6 comments

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()

jpadilla avatar Mar 31 '15 17:03 jpadilla

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 avatar Jun 17 '16 19:06 chris-erickson

@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.

jpadilla avatar Jun 17 '16 20:06 jpadilla

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.).

tgroshon avatar Jan 17 '17 18:01 tgroshon

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.

dhrp avatar Jun 18 '17 19:06 dhrp

I'm down with reviewing a PR that uses logging instead of warnings like discussed in #23.

jpadilla avatar Jun 19 '17 15:06 jpadilla

FTR at my company we have written a small lib to abstract various settings systems including dotenv; no warnings! https://github.com/caravancoop/configstore/

merwok avatar Feb 13 '18 00:02 merwok