Skip to content
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

Cannot read property 'python' of undefined #2085

Closed
jrhubott opened this issue Jun 19, 2020 · 26 comments
Closed

Cannot read property 'python' of undefined #2085

jrhubott opened this issue Jun 19, 2020 · 26 comments

Comments

@jrhubott
Copy link

jrhubott commented Jun 19, 2020

Does this occur consistently? Yes
Repro steps:

  1. Launch the docker debug task
  2. Only occurs if you are running under a workspace, doesn’t occur without one. When running without it fails with the unable to detect debugger in Python extension error.
  3. All tasks are present in tasks.yml

Action: docker-launch
Error type: TypeError
Error Message: Cannot read property 'python' of undefined

Version: 1.3.1
OS: darwin
OS Release: 19.5.0
Product: Visual Studio Code
Product Version: 1.46.15
Language: en

Call Stack
PythonDebugHelper.resolveDebugConfiguration extension.bundle.js:423:354415
processTicksAndRejections task_queues.js:85:5
async DockerDebugConfigurationProvider.resolveDebugConfigurationInternal extension.bundle.js:492:321098
extension.bundle.js:492:320854extension.bundle.js:492:320854
@bwateratmsft
Copy link
Contributor

@jrhubott This looks the same as #2077. Did you create the Docker launch config using the commands Docker: Add Dockerfiles to workspace or Docker: Initialize for debugging? If not, you need to use those as it is necessary to also create the task configurations.

@azagarelz
Copy link

Same issue here.

I'm trying within a workspace, all tasks are present and have been created by running Docker: Add Dockerfiles to workspace

Does this occur consistently? Yes

Action: docker-launch
Error type: TypeError
Error Message: Cannot read property 'python' of undefined

Version: 1.3.1
OS: darwin
OS Release: 19.4.0
Product: Visual Studio Code
Product Version: 1.46.1
Language: en

Call Stack
PythonDebugHelper.resolveDebugConfiguration extension.bundle.js:423:354415
processTicksAndRejections task_queues.js:85:5
async DockerDebugConfigurationProvider.resolveDebugConfigurationInternal extension.bundle.js:492:321098
extension.bundle.js:492:320854extension.bundle.js:492:320854

@bwateratmsft
Copy link
Contributor

@azagarelz can you share your tasks and launch configs?

@jrhubott
Copy link
Author

launch.json

    "version": "0.2.0",
    "configurations": [{
            "name": "Python: torrent-manager.py",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/torrent-manager.py",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Autoremovetorrents",
            "type": "python",
            "request": "launch",
            "module": "autoremovetorrents.main",
            "args": [
                "--view" , "--host=http://192.168.0.60:9091"
            ]
        },
        {
            "name": "Docker Container Debug",
            "type": "docker",
            "request": "launch",
            "preLaunchTask": "docker-run: debug",
            "python": {
                "pathMappings": [{
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "/app"
                }],
                "projectType": "general"
            }
        }
    ]
}

tasks.json

"version": "2.0.0",
	"tasks": [
		{
			"type": "docker-build",
			"label": "docker-build",
			"platform": "python",
			"dockerBuild": {
				"tag": "jrhubott/autoremove-torrents:debug",
				"dockerfile": "${workspaceFolder}/Docker/Dockerfile",
				"context": "${workspaceFolder}",
				"pull": true
			}
		},
		{
			"type": "docker-run",
			"label": "docker-run: debug",
			"dependsOn": [
				"docker-build"
			],
			"python": {
				"file": "-m autoremovetorrents.main --conf /config/config.yml --view"
			}
		}
	]
}

@bwateratmsft
Copy link
Contributor

@jrhubott You're using the "file" parameter to choose a module in the run task. Can you try changing that to "module"?

		{
			"type": "docker-run",
			"label": "docker-run: debug",
			"dependsOn": [
				"docker-build"
			],
			"python": {
				"module": "autoremovetorrents.main",
                                "args": ["--conf", "/config/config.yml", "--view"]
			}
		}

@adealdag
Copy link

adealdag commented Jun 26, 2020

I'm having the same issue since VS Code upgraded docker extension to 1.3.1

launch.json

{
    "configurations": [
        {
            "name": "Docker: Python - Flask",
            "type": "docker",
            "request": "launch",
            "preLaunchTask": "docker-run: debug",
            "python": {
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}",
                        "remoteRoot": "/app"
                    }
                ],
                "projectType": "flask"
            }
        }
    ]
}

tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "docker-build",
			"label": "docker-build",
			"platform": "python",
			"dockerBuild": {
				"tag": "api:latest",
				"dockerfile": "${workspaceFolder}/Dockerfile",
				"context": "${workspaceFolder}",
				"pull": true
			}
		},
		{
			"type": "docker-run",
			"label": "docker-run: debug",
			"dependsOn": [
				"docker-build"
			],
			"dockerRun": {
				"env": {
					"FLASK_APP": "c_link_api.py"
				},
				"ports": [
					{
						"containerPort": 5000,
						"hostPort": 32790,
						"protocol": "tcp"
					}
				]
			},
			"python": {
				"args": [
					"run",
					"--no-debugger",
					"--no-reload",
					"--host 0.0.0.0",
					"--port 5000"
				],
				"module": "flask"
			}
		}
	]
}

Also, I cannot install another version of docker extension, every time I try it fails with "Server returned 404"

@bwateratmsft
Copy link
Contributor

I'm still not able to reproduce even with the exact same configuration that @adealdag shared. @adealdag, what OS and Python version are you using? Also, what version of the Python extension?

I'm on Windows, Python 3.8.2, Python extension 2020.6.90262.

Regarding the failure to install other versions, that looks like this bug: microsoft/vscode#99699

@adealdag
Copy link

I'm running VS Code in Mac Os Catalina, Python 3.7.3, Python extension v2020.6.90262

@bwateratmsft
Copy link
Contributor

@adealdag Do you have anything in settings.json for the Python or Docker extensions?

@adealdag
Copy link

@adealdag Do you have anything in settings.json for the Python or Docker extensions?

Nothing fancy:

{
    "python.pythonPath": "/usr/bin/python3",
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": true,
    "python.linting.flake8Enabled": false,
    "python.linting.mypyEnabled": true
}

BTW, I have manually installed docker 1.2.1 from VSIX file, and everything started working again. Nothing else changed, just the version of the extension.

@bwateratmsft bwateratmsft assigned bwateratmsft and unassigned haniamr Jun 29, 2020
@bwateratmsft
Copy link
Contributor

bwateratmsft commented Jun 29, 2020

@adealdag I'm stumped. I just can't figure it out. Would you be willing to try with an alpha build?

The only possible explanations I can come up with are:

  1. Some non-printing characters in the task labels or pre-launch task
  2. VSCode not giving us proper config info on tasks--this seems potentially possible given the bugs they have had lately relating to over-caching of tasks and launch configs (these bugs are basically what 1.46.1 are about). However, there may still be issues left in 1.46.1.

@adealdag
Copy link

adealdag commented Jul 3, 2020

@adealdag I'm stumped. I just can't figure it out. Would you be willing to try with an alpha build?

Sure! As long as I can roll back to the working version after the test, it's peerfectly OK for me.

I'm kind of busy these days, but let me know how I can help on this and I'll try to do that as soon as I can.

@pgross41
Copy link

pgross41 commented Jul 7, 2020

BTW, I have manually installed docker 1.2.1 from VSIX file, and everything started working again. Nothing else changed, just the version of the extension.

Downgrading the extension also fixed things for me. I have never done this before so it was hard to figure out what I was doing wrong, the main issue I had was it just hung there doing nothing. I tried everything, at some point my config threw the 'python' of undefined error but I don't remember how I reproduced that. After I made fresh launch/tasks files and downgraded the extension it worked right away.

This is probably an Issue for the extension but something I noticed is 1.3.1 wasn't using any of my args. In 1.2.1 it ran this (good):

docker run -dt -P --name "dvr163hass-dev" -e "PTVSD_LOG_DIR=/dbglogs" --label "com.microsoft.created-by=visual-studio-code" -v "C:\Users\pgros\Downloads\VSCode\data\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\old_ptvsd:/pydbg:ro" -v "C:\Users\pgros\AppData\Local\Temp\dvr163-hass:/dbglogs:rw" -p "5678:5678" --entrypoint "python" "dvr163hass:latest" /pydbg/ptvsd --host 0.0.0.0 --port 5678 --wait /app/email2dropbox.py --log_level 10 /dev/dvr163-email.txt <

In 1.3.1 though it looks like this (bad):

docker run -dt -P --name "dvr163hass-dev" --label "com.microsoft.created-by=visual-studio-code" -v "/home/patrick/.vscode-server/extensions/ms-python.python-2020.6.91350/pythonFiles/lib/python/debugpy:/debugpy:ro" --entrypoint "python" "dvr163hass:latest" <

Notice the new version didn't include my log_level arg, it looks like it's missing some others too like port and wait.

@bwateratmsft
Copy link
Contributor

bwateratmsft commented Jul 7, 2020

the main issue I had was it just hung there doing nothing.

@pgross41 Are you on Insiders? There was a bug in VSCode Insiders (now fixed and released) that caused our tasks to hang forever; this affected all versions of the Docker extension.

@bwateratmsft
Copy link
Contributor

@adealdag @pgross41 I have prepared a build based on this branch, which adds a bunch of info to the Output tab for the Docker extension. This should help us get a better idea what is going on.

Here's the build: https://dev.azure.com/ms-azuretools/AzCode/_build/results?buildId=22277&view=results
And a direct link to a zip file with the VSIX from it: https://dev.azure.com/ms-azuretools/534e1e1c-b364-44d0-b5ee-dce879a5106e/_apis/build/builds/22277/artifacts?artifactName=vsix&api-version=5.1&%24format=zip

You can install that VSIX by running the command "Extensions: Install from VSIX..."

When you run a Python debug operation it will spit out a lot of extra logs in the Output tab for Docker, can you paste that output, along with the tasks.json and launch.json you have?

@pgross41
Copy link

pgross41 commented Jul 8, 2020

@bwateratmsft I'm not an Insiders I suspect the hanging is because the container is using python as the entrypoint and it's stuck at an interactive prompt. Here is my configuration:

tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "docker-build",
      "label": "docker-build",
      "platform": "python",
      "dockerBuild": {
        "tag": "dvr163hass:latest",
        "dockerfile": "${workspaceFolder}/Dockerfile",
        "context": "${workspaceFolder}",
        "pull": true
      }
    },
    {
      "type": "docker-run",
      "label": "docker-run: debug",
      "dependsOn": [
        "docker-build"
      ],
      "python": {
        "args": ["--key", "xxxxxxxxxxxxxxxxxxxxxxxxxxx", "--log_level", "10", "/dev/dvr163-email.txt"],
        "file": "/app/email2dropbox.py"
      }
    }
  ]
}

launch.json
{
  "configurations": [
    {
      "name": "Docker: Python - email2dropbox",
      "type": "docker",
      "request": "launch",
      "preLaunchTask": "docker-run: debug",
      "python": {
        "pathMappings": [
          {
            "localRoot": "${workspaceFolder}/root/app",
            "remoteRoot": "/app"
          }
        ],
        "projectType": "general"
      }
    }
  ]
}

I just did it with 1.2.1 and it worked as expected. Upgraded to 1.3.1 and the issue recreated. More info:

1.3.1

Here is the run command it's using from Windows (I was using WSL for 1.3.1 last night but it's basically the same string).

docker run -dt -P --name "dvr163hass-dev" --label "com.microsoft.created-by=visual-studio-code" -v "c:\Users\pgros\Downloads\VSCode\data\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\debugpy:/debugpy:ro" --entrypoint "python" "dvr163hass:latest" <

I also get this error (Windows only... does not happen in WSL)
image

1.3.2-alpha

It is displaying this error:
image

With this output:
Error: The docker-build task detection didn't contribute a task for the following configuration:
{
    "type": "docker-build",
    "label": "docker-build",
    "platform": "python",
    "dockerBuild": {
        "tag": "dvr163hass:latest",
        "dockerfile": "${workspaceFolder}/Dockerfile",
        "context": "${workspaceFolder}",
        "pull": true
    }
}
The task will be ignored.
Error: The docker-run task detection didn't contribute a task for the following configuration:
{
    "type": "docker-run",
    "label": "docker-run-debug",
    "dependsOn": [
        "docker-build"
    ],
    "python": {
        "args": [
            "--key",
            "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "--log_level",
            "10",
            "/dev/dvr163-email.txt"
        ],
        "file": "/app/email2dropbox.py"
    }
}
The task will be ignored.

@bwateratmsft
Copy link
Contributor

Awesome, this is really helpful. Thanks @pgross41!

The "'debugLauncherPath' must be str" error: Double check you have the latest version of the Python extension. Also, did you do anything to disable the new debugpy debugger experiment? Their as-released code still will not return anything when we query the debugger path if the debugpy experiment is disabled.

RE the tasks--In your pasted tasks.json, it has the debug task being named "docker-run: debug", whereas in that task output from 1.3.2-alpha it shows "docker-run-debug". Did you change the task name in either launch.json or tasks.json, or is that something weird VSCode is doing?

@bwateratmsft
Copy link
Contributor

@pgross41 @adealdag I talked to @alexr00, she suggested trying VSCode Insiders (make sure to get it up-to-date as there were some other issues with Insiders builds from earlier this month). She said there were some old task issues that have been fixed in Insiders that might be the root causes of what you're seeing.

If time permits, can you try out Insiders with the 1.3.2-alpha from earlier, 1.3.1, and 1.2.1? If you only have time for one then try 1.3.2-alpha. 😄

Thanks for bearing with us and for all your help!

@pgross41
Copy link

pgross41 commented Jul 8, 2020

@bwateratmsft sorry for changing the task name on you. Yes that was me, I was trying to see if the space in the label was causing it to break.

Okay it's been a slow day at work today 😁 I upgraded to Insiders and tested all the Docker extensions:

1.2.1 - Works just like it has been

1.3.1 - It works and the terminal is doing something new. It builds in 1: Task - docker-build then changes to 1: Task - docker-run: debug and it shows the "bad" docker run command:

docker run -dt -P --name "dvr163hass-dev" --label "com.microsoft.created-by=visual-studio-code" -v "c:\Users\pgros\.vscode-insiders\extensions\ms-python.python-2020.6.91350\pythonFiles\lib\python\debugpy:/debugpy:ro" --entrypoint "python" "dvr163hass:latest" <

but wait there's more, that terminal just sits there like always (seems to be hanging like before) but then a new 2: Python Debug Console terminal opens with my arguments in it:

& 'C:\Users\pgros\AppData\Local\Programs\Python\Python37\python.exe' 'c:\Users\pgros\.vscode-insiders\extensions\ms-azuretools.vscode-docker-1.3.1\resources\python\launcher.py' '61472' '--' '/app/python/email2dropbox.py' '--key' 'xxxxxxxxxxxxxxxxxxxxxxxxxxx' '--log_level' '10' '/app/dev/dvr163-email.txt' 'dvr163hass-dev'
docker exec -d dvr163hass-dev python /debugpy/launcher host.docker.internal:61472 -- /app/python/email2dropbox.py --key xxxxxxxxxxxxxxxxxxxxxxxxxxx --log_level 10 /app/dev/dvr163-email.txt

1.3.2-alpha

This is throwing the same "Could not find task" error as above. Something worth noting is I have shell tasks in tasks.json that are not displayed in the output. It's only the docker tasks that say Error: The docker-build task detection didn't contribute a task for the following configuration ... The task will be ignored.


I will likely continue to develop with 1.2.1 for now but I'm happy to continue helping troubleshoot. Seems like 1.3.1 is stable on Insiders but 1.3.2-alpha is not stable anywhere.

@bwateratmsft
Copy link
Contributor

I remember now why the discrepancy between exists between what is shown in the terminal (not having the args) vs. what is run in that "Python Debug Console". When doing debugging, we do a docker run command with just a default entrypoint--in this case, "python"--to start the container without actually starting the process. This leaves open a Python shell doing nothing. It's not frozen, it's just doing nothing. We do the same for .NET Core (though not Python, just a regular shell). In .NET Core, this is the difference between the debug and not-debug docker-build and docker-run configurations.

The Python debug configuration, however, resolves and includes the args from the docker-run task, and passes them over to the Python debug adapter in the Python extension, which executes the command you're seeing in the Python Debug Console terminal window. It is that lookup that is failing--finding the docker-run task, in order to get the arguments. In 1.2.1 and 1.3.1 there is a separate issue (fixed in that 1.3.2-alpha) build wherein the debug config resolving (which is the first step of the process, before the tasks) fails if no docker-run task is found, and then you'll see the "Cannot read property 'python' of undefined". In 1.3.2-alpha, that bug is fixed, so debug config resolving "succeeds" (without having found the docker-run task), but VSCode is failing to resolve the task, so it shows that "task detection didn't contribute a task..." error.

@alexr00 It sounds like the Insiders build did fix at least one of the causes of this issue (1.3.1 failed in public build but succeeded in Insiders build). However, there was no change in the task logic between 1.3.1 and 1.3.2-alpha, so something else must still be going on...

@bwateratmsft
Copy link
Contributor

bwateratmsft commented Jul 8, 2020

@pgross41 I had an idea of what could have gone wrong (basically, any failure during extension activation would result in the task handler not being registered; there are changes in 1.3.2 related to that). I made a new build of that 1.3.2-alpha, in theory it should behave like 1.3.1 and therefore work in Insiders.

The build: https://dev.azure.com/ms-azuretools/AzCode/_build/results?buildId=22392&view=results
The VSIX: https://dev.azure.com/ms-azuretools/_apis/resources/Containers/4311688/vsix?itemPath=vsix%2Fvscode-docker-1.3.2-alpha.vsix

@bwateratmsft
Copy link
Contributor

No further changes to be made in 1.4.0; hopefully this issue goes away between the fixes already in VSCode 1.47 and in Docker extension 1.4.0.

@bwateratmsft bwateratmsft modified the milestones: 1.4.0, 1.5.0 Jul 13, 2020
@pgross41
Copy link

I've actually been using Insiders with 1.3.1 with no issues

@bwateratmsft
Copy link
Contributor

I've actually been using Insiders with 1.3.1 with no issues

That's good to hear. Hopefully Alex's fixes took care of most of the issues!

@bwateratmsft
Copy link
Contributor

It's hard to tell but it appears from telemetry that the rate of this issue is declining. Part of the difficulty is that the error is exactly the same in this case and also the user-error case where they did not add the tasks.

For now I'll close this issue as fixed, but please let us know if anyone sees this problem return!

@bwateratmsft
Copy link
Contributor

We have released Docker 1.4.0. We're pretty sure this issue is fixed in that build, let us know if you see otherwise!

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants