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

Proxies created in proxies.json are considered as function at runtime and raise an Exception "IndexError: tuple index out of range" #802

Closed
chapoub opened this issue Jan 6, 2021 · 4 comments
Assignees

Comments

@chapoub
Copy link

chapoub commented Jan 6, 2021

Investigative information

  • Timestamp: 06/01/2021
  • Function App name: Azure_API_Project
  • Function name(s) (as appropriate): Azure Functions Core Tools
  • Core Tools version: 3.0.3160

Repro steps

1./ Create a proxies.json file stored in the root of an azure functions' project (according to the following sentence found in https://docs.microsoft.com/en-us/azure/azure-functions/functions-proxies: "The proxies that you configure are stored in a proxies.json file, which is located in the root of a function app directory. You can manually edit this file and deploy it as part of your app when you use any of the deployment methods that Functions supports.").
2./ Copy the following value in this file (example found in https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-serverless-api):
{
"$schema": "http://json.schemastore.org/proxies",
"proxies": {
"GetUserByName" : {
"matchCondition": {
"methods": [ "GET" ],
"route": "/api/users/{username}"
},
"responseOverrides": {
"response.statusCode": "200",
"response.headers.Content-Type" : "application/json",
"response.body": {
"name": "{username}",
"description": "Awesome developer and master of serverless APIs",
"skills": [
"Serverless",
"APIs",
"Azure",
"Cloud"
]
}
}
}
}
}
3./ Run your project (I use vscode and I click on the button "Attach to Python Functions" to do so)

Expected behavior

You should get a list with your Functions name, the CRUD operations they support (GET, POST, ...), and the URL associated to it.
Then you should get a message
"For detailes output, run func with --verbose flag. Host lock lease acquired by instance ID 'XXXX'. Worker process started and initialized."

Actual behavior

The proxies name stored in proxies.json are appearing along with the Functions name, so in our example case GetUserByName is added in the list.
After the message "Worker process started and initialized" appears after a short moment you should see an error popping saying "Worker failed to function id XXX. Result: Failure. Exception: IndexError: tuple index out of range."

Known workarounds

The worker is failing with function GetUserByName which is a proxy.
In order to discover that I navigated to the place the error is happening which location is
AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.7/WINDOWS/x64\azure_functions-worker\loader.py
l63, of the loader.py file, it is trying to assign the following:
last_part = rel_script_path.parts[-1]

parts is the tuple raising the out of range exception, this tuple should be filled with the parameter scriptFile when creating a function in function.json, please find the example below which I got on https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python:
{
"scriptFile": "init.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}

In proxies.json, we don't define such a scriptFile parameter, and this is why the exception is raised.

Contents of the requirements.txt file:

azure-functions
azure.identity
azure-keyvault-secrets

Related information

https://docs.microsoft.com/en-us/azure/azure-functions/functions-proxies
https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-serverless-api
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-python

@vrdmr
Copy link
Member

vrdmr commented Feb 10, 2021

@stefanushinardi - Please take a look at it.

@anthonychu
Copy link
Member

Sounds similar to or same as something @mhoeger helped fix in Node. Azure/azure-functions-nodejs-worker#299

@Hazhzeng
Copy link
Contributor

Thanks @chapoub for raising this issue. Confirmed that this issue happens if there's a proxies.json in the project root. It will raise an error.

Result: Failure
Exception: IndexError: tuple index out of range
Stack:   File "\azure-functions-core-tools\bin\workers\python\3.7\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 275, in _handle__function_load_request
    func_request.metadata.entry_point)
  File "\azure-functions-core-tools\bin\workers\python\3.7\WINDOWS\X64\azure_functions_worker\utils\wrappers.py", line 32, in call
    return func(*args, **kwargs)
  File "\azure-functions-core-tools\bin\workers\python\3.7\WINDOWS\X64\azure_functions_worker\loader.py", line 63, in load_function
    last_part = rel_script_path.parts[-1]

The function is still accessible, but since a proxy is missing scriptFile field in function.json, the loader fails to handle the proxy loading (I think it should be a no-op since the proxy shares the same code as the HttpTrigger).

I attach the repo in the following link, may need further investigation before implementing a fix in Python Worker.
PythonProxy.zip

@vrdmr
Copy link
Member

vrdmr commented Mar 22, 2022

Proxies are not available in v4 and this feature can be closed.

@vrdmr vrdmr closed this as completed Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants