Flask: Environment variables in .env file not refreshing after re-running application

Created on 29 Aug 2018  路  3Comments  路  Source: pallets/flask

TLDR;
Use PIPENV_DONT_LOAD_ENV=1 pipenv shell

Expected Behavior

Flask sets/overrides environment variables specified in .env each time flask run is run.

Actual Behavior

Flask is unaware that the .env file in my project directory has changed and does not refresh it's own environment variables.

Environment

  • Pipenv
  • Python version: 3.6.5
  • Flask version: 1.0.2
  • Werkzeug version: 0.14.1

Most helpful comment

Solved it! As documented here PIPENV_DONT_LOAD_ENV=1 pipenv shell solved my issue. It must be pipenv trying to optimistically cache .env or perhaps a race condition between pipenv and flask-cli?

All 3 comments

The file is read once on startup, there is no caching involved - are you sure you aren't overriding the value in your code?
Please provide a minimal testcase to reproduce your problem.

@ThiefMaster It's possible it's an issue with pipenv? All i'm doing is changing the FLASK_ENV variable in my .env file from production to development and re-running flask run, but not seeing the application change modes.

Solved it! As documented here PIPENV_DONT_LOAD_ENV=1 pipenv shell solved my issue. It must be pipenv trying to optimistically cache .env or perhaps a race condition between pipenv and flask-cli?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lnielsen picture lnielsen  路  3Comments

fb picture fb  路  5Comments

ghost picture ghost  路  3Comments

westonplatter picture westonplatter  路  3Comments

chuanconggao picture chuanconggao  路  4Comments