Repository navigation
Debug configuration env variables should overwrite env variables defined in .env file #16984
Description
Activity
@lowercase00
The way you're defining things, I think your
"cwd"must be at a pretty specific place forapp/uwsgi.pyto be picked up, yet, you're not defining it... can you try to specify the"cwd"in the launch config to be the folder which containsapp/uwsgi.pyto see if it works?Note: it did work for me when the
cwdwas properly specified...Fabio Zadrozny (@fabioz) thanks, I did try with ${workspaceFolder} before the app/uwsgi.py also didn't work, I'll try setting cmd to set how it goes
Just tried with
cmdand also didn't work.
What I find weird is theapplication. Is not that is not finding the Flask App, it's not even looking forapp/uwsgi.pyis only looking forapplication.pyas if theenvvar is not being read.Weird enough, I can't replicate the issue on a newly create Flask project with exactly the same folder structure. I've already created and recreated the venv and everything else that I could (mypy, pyenv, vscode folder etc). Any tips ou troubleshooting this? I've got no messages at all at the developers console, so really no idea what could be the issue.
Are there any version differences in the packages between the two environments, if you look inside
.venv/site-packages?So finally found out the issue. I had an old
FLASK_APP=application.pyon my.envfile, and it was overwriting theenvvars I was passing in thelaunch.json. I'm not sure if it's possible for the extension to control the order in which env vars are loaded, so not sure if anything different could have been done. If it is, I would suggest that theenvvars in thelaunch.jsonfile to be top priority and overwrite otherenvvars, instead of the other way around.From debugpy perspective, it doesn't actually know anything about
.env- that's something the extension handles, basically, by reading the file and then injecting those variables into your debug config. So this would need to be handled in vscode-python.But I agree that launch.json should take priority -
.envis supposed to define the default values for the entire folder/workspace, but individual debug configurations should be able to override that as needed.- addedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Aug 16, 2021 - addedbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugregressionBug didn't exist in a previous releaseBug didn't exist in a previous releaseand removedtriage-neededNeeds assignment to the proper sub-teamNeeds assignment to the proper sub-team
on Aug 17, 2021 - addedimportantIssue identified as high-priorityIssue identified as high-priorityand removedimportantIssue identified as high-priorityIssue identified as high-priority
on Sep 29, 2021 - changed the title
[-]Flask debugger not reading the correct env var[/-][+]Debug configuration env variables should overwrite env variables defined in .env file [/+]on Nov 29, 2021 - addedverifiedVerification succeededVerification succeeded
on Nov 29, 2021 - locked as resolved and limited conversation to collaborators
on Dec 30, 2021
Environment data
python.languageServersetting: "Default"Expected behaviour
"env" portion of
launch.jsondoesn't seem to work.When trying to launch a Flask application I have the following tree structure:
My
launch.jsonfile is:When running the debugger Flask says it can't find
applicationand the first line shows:So from what I can understand it is as if the env var "FLASK_APP=app/uwsgi.py" is not being read, so it loads the default "application", and can't find the app.
Tried without the debugger and works fine (
FLASK_APP=app/uwsgi.py; flask run).Another weird thing is that when I set
it goes as for as running the server, but when trying to reach any endpoint it says
flask.cli.NoAppException: Could not import "application"..If I remove the
FLASK_ENVline it doesn't even run the server and gives me an error:Error: Could not import "application".