microsoft / vscode-azurefunctions

Azure Functions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions
MIT License
291 stars 134 forks source link

There is an error when executing function for a Python project with empty request body #2608

Closed v-mengwe closed 3 years ago

v-mengwe commented 3 years ago

OS: Win10 Build Version: 20201215.1

Repro Steps:

  1. Install Visual Studio Codespaces extension -> Connect to a codespace -> Install the Function extension in the codespace.
  2. Create a new python project with "HTTP trigger" -> Debug.
  3. Expand the Local Project tree view and right click on the function -> Select "Execute Function Now..." -> Delete the default request body -> Press enter.
  4. Check whether execute function successfully.

Expect: Succeed to execute function without any error.

Actual: There is an error when executing function and the notification is different with other projects. fun1 fun11

[2020-12-17T02:41:11.444Z] Executed 'Functions.HttpTrigger1' (Failed, Id=55ec7fe4-e222-414f-8447-a133b1736097, Duration=40923ms)
[2020-12-17T02:41:11.445Z] System.Private.CoreLib: Exception while executing function: Functions.HttpTrigger1. System.Private.CoreLib: Result: Failure
[2020-12-17T02:41:11.445Z] Exception: AttributeError: 'str' object has no attribute 'get'
[2020-12-17T02:41:11.446Z] Stack:   File "/usr/lib/azure-functions-core-tools-3/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 347, in _handle__invocation_request
[2020-12-17T02:41:11.446Z]     call_result = await self._loop.run_in_executor(
[2020-12-17T02:41:11.447Z]   File "/opt/python/3.8.6/lib/python3.8/concurrent/futures/thread.py", line 57, in run
[2020-12-17T02:41:11.447Z]     result = self.fn(*self.args, **self.kwargs)
[2020-12-17T02:41:11.448Z]   File "/usr/lib/azure-functions-core-tools-3/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 511, in __run_sync_func
[2020-12-17T02:41:11.449Z]     return func(**params)
[2020-12-17T02:41:11.450Z]   File "/home/codespace/workspace/function/py1/HttpTrigger1/__init__.py", line 16, in main
[2020-12-17T02:41:11.450Z]     name = req_body.get('name')
[2020-12-17T02:41:11.451Z] .

More Info: This issue doesn't reproduce for JavaScript/TypeScript/C#/PowerShell project. image

ejizba commented 3 years ago

This repros for me without Codespaces and the important part is that it only happens if you delete the default request body. The other languages probably just have more error-checking in the default template than Python 🤷‍♂️ Since this works fine if you use the default request body, will close as "wont-fix"