-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Problem with overwriting variables from .env #23856
Comments
Can you try adding
into your settings.json and see if you still experience this behavior? Perhaps first try with just "Python: Clear Cache reload" and see if your environment variables from .env gets updated, if that does not happen THEN try to opt out(by adding setting) and reload again. |
Is this related to #23280 ? |
@anthonykim1 Yeah. The issue seems closely related to what I observed in #23280, where environment variables set in the terminal do not update after modifying the .env file. Both issues highlight the persistent nature of environment variables in the terminal even after changes to the .env file or deactivating the Python extension. This behavior can be confusing, especially since the documentation doesn't clearly outline this. |
Hi @waterstark Would https://code.visualstudio.com/docs/python/environments#_environment-variables help you better understand .env with Python extension? Curious to hear what you think. Thanks |
Thanks for your contribution! It seems that the documentation explains how .env files are used when the extension is active, but doesn't mention what happens after the extension is deactivated or when updates are made to the .env file during this state.
…On Sep 17, 2024, 2:40 PM -0700, Anthony Kim ***@***.***>, wrote:
Hi @waterstark Would https://code.visualstudio.com/docs/python/environments#_environment-variables help you better understand .env with Python extension? Curious to hear what you think. Thanks
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
I have the same issue. Setting the optOut didn't seem to help. |
I just ran into this error with this flow:
This is especially frustrating because nextjs resolves env vars in priority of shell above .env files, so even if I set the new val in the .env file, nextjs still picks up the stale value in my shell that ms-python set, and and I seem to be able to find no way to get it to get ms-python to forget that old value. Can you give us a workaround to get ms-python to forget about all env vars it has cached? Long term, updating the env vars when the .env file changes I would hope would be top priority, without this it is like if I bought an oven and after I turn it on the first time, I will only ever be able to use it at that same temperature. |
Behaviour
If I restart VS Code and modify the .env file, the new variable values from the .env file do not get applied to my FastAPI application.
Steps to reproduce problem:
${workspaceFolder}/.env
MY_VAR=1
.MY_VAR
in the .env file toMY_VAR=2
.echo $MY_VAR
in the terminal.Description
I had to spend around two days troubleshooting an issue where VS Code automatically sets environment variables at terminal launch, causing non-obvious code behavior.
Considering that most of the audience are junior and middle-level developers, I believe many might face this problem. Is there a way to make this feature more explicit, such as prompting the user to enable or disable this setting? Or maybe we can make it opt-in instead of opt-out?
Diagnostic data
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)The text was updated successfully, but these errors were encountered: