Changes to environment variables in `python.envFile` not getting picked up
kartikgupta-db opened this issue · 15 comments
Applies To
- Notebooks (.ipynb files)
- Interactive Window and/or Cell Scripts (.py files with #%% markers)
What happened?
The extension is supposed to load environment variables from python.envFile
setting (#9691).
But the variables seems to be cached somewhere. It takes multiple restarts of the kernel and restart of the entire notebook to pickup the latest changes.
Steps to reproduce
- Create a notebook
- Add some code like
import os
print(os.environ["TEST_ENV_VAR"])
- Create a
.env
file (in the location pointed bypython.envFile
variable. - Add the TEST_ENV_VAR to the file. Run the cell (which starts the kernel). The variable is loaded correctly.
- Change (or remove) TEST_ENV_VAR.
- Restart the kernel and run the cell -> the variable is still found (this error happens very frequently, but NOT everytime).
- Restart the notebook -> if you are lucky the variable is not found, otherwise the variable is still found.
Video
Env.var.bug.mp4
VS Code Version
1.79.2
Jupyter Extension Version
v2023.5.1101742258
Jupyter logs
No response
Coding Language and Runtime Version
No response
Language Extension Version (if applicable)
No response
Anaconda Version (if applicable)
No response
Running Jupyter locally or remotely?
Local
You are using an old version of the Jupyter extension
Please could you update to the latest version of Jupyter and python extension and try to replicate this issue
@DonJayamanne I am able to reproduce this with v2023.7.1002162226
now. Exactly the same issue. Requires multiple notebook/kernel restarts for the env to be refreshed. I suspect some kind of caching here?
@binderjoe can you take a look? We need this for the Dtabricks VS Code extension.
@karrtikr if we enable verblose logging in Python extension will the logs show that Python extension has detected changes to the .env file? or do we need add logging for that?
Changes aren't logged right now as historically this has been working fine, but logging can be added here: https://github.com/microsoft/vscode-python/blob/d17ebcec3a4f202ceb4715040343e97adbd103fe/src/client/common/variables/environmentVariablesProvider.ts#L187
FWIW, the env file changes are being picked immediately, when the code is run using "Run Python File" or "Debug Python File" options.