azure-functions-python-worker: [BUG] Azure function python v2 not visible in Azure Portal after deployment

Follow the steps mentioned in the document to deploy the function. https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python?pivots=python-mode-decorators

Investigative information

Please provide the following:
  • Timestamp: always happening
  • Core Tools version: V1.2.0, through VS code extension
  • VS code- 1.83.1

Repro steps

Provide the steps required to reproduce the problem:
  1. Follow steps as in above doc
  2. Create a blob trigger function
  3. add the below requirements.txt
  4. add the below to app.py
  5. test locally- runs perfectly!
  6. deploy to azure using VS code, right click “deploy to azure”, once successful - DOESNT SHOW IN PORTAL.

–>

Expected behavior

Provide a description of the expected behavior.
  1. The function should be visible on portal
  2. The function should be executed once blob is uploaded into the blob-storage
  3. Expected to work as it behaves on local.

Actual behavior

Provide a description of the actual behavior observed.
  1. Cannot find the function
  2. The function doesnt execute when the endpoint is hit
  3. the local test works but the deployed function doesnt
  4. fails in consumption plan
  5. fails in app service plan

Known workarounds

Provide a description of any known workarounds.

No workarounds

Contents of the requirements.txt file:

Provide the requirements.txt file to help us find out module related issues.

Files at the end

Related information

Provide any related information
Source
import azure.functions as func
import logging
import os

#qdrant
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams,PointStruct 

#encoder for vecotrizing embeddings
from sentence_transformers import SentenceTransformer

from langchain.document_loaders import PyPDFLoader
from langchain.document_loaders import DirectoryLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter

#https://stackoverflow.com/questions/75627362/azure-functions-python-error-no-job-functions

app = func.FunctionApp()

@app.blob_trigger(arg_name="myblob", path="mycontainer",
                               connection="BlobStorageConnectionString") 
def blob_trigger(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob"
                f"Name: {myblob.name}"
                f"Blob Size: {myblob.length} bytes")


# DO NOT include azure-functions-worker in this file
# The Python Worker is managed by Azure Functions platform
# Manually managing azure-functions-worker may cause unexpected issues

azure-functions
-f https://download.pytorch.org/whl/torch_stable.html
torch==1.13.1+cpu
torchvision==0.14.1+cpu
torchaudio==0.13.1
sentence_transformers==2.2.2
langchain==0.0.274
qdrant_client==1.2.0
pypdf==3.9.0

Several customers reported this issue here, which was closed with no answer. https://github.com/Azure/azure-functions-python-worker/issues/1262 Please kindly look in and suggest.

Tagging you from the closed issue where the MS team hasn’t been responding. @Otimkev @andrewmmm @jsm-NK @aadamsx @JarroVGIT @SiddheshDesai06

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 51 (8 by maintainers)

Most upvoted comments

Plus one.

It is very frustrating to debug issues that occur outside of the function definition.

For example, import errors, missing dependencies, or issues with the binding and trigger definitions.

We are essentially flying blind when trying to debug these problems.

Azure Functions should provide more access to logging that can lend a light to these issues.

Hi all,

I was running into the same issues mentioned above. I was using the Deployment Center in the Azure Function App to connect it to my GitHub, and no matter which packages I installed inside my requirements.txt file—even something as common as requests—the function trigger would not show up in the portal when deployed because it couldn’t find the packages.

The solution I found was to zip up the library packages during the GitHub build instead of letting Oryx do the remote build. Here are the changes I made to the GitHub workflow file to achieve this:

  1. Inside the “Install dependencies” step of the build job, change the pip install command pip install --target=".python_packages/lib/site-packages" -r requirements.txt
  2. Inside the “Zip artifact for deployment” step of the build job, change the zip command so it includes the python_packages zip release.zip .python_packages ./* -r
  3. Inside the “Deploy to Azure Functions” step of the deploy job, change these values so it doesn’t do a remote build scm-do-build-during-deployment: false enable-oryx-build: false

This way you can still use the V2 programming model and can use Github Actions instead of VSCode to deploy to the Azure Function.

@saikumaru We are actively addressing this matter to offer users more clarification on such issues. We will provide an update once we make progress on this. I am closing this issue for now. Thanks

@jmandivarapu If you are still facing the issue, please open new issue. Thanks

Why was this issue closed while this clearly is an ongoing issue? Is there an other topic where we can follow the progress on this issue?

I am having similar issues where …

  1. I deployed the python functions using VS code (It works and all the functions show up including all the files)
  2. Deploying using the Azure Devops - App files got updated but NO FUNCTIONS

Tried all possible plans but none of seams to work. I am currently using Python 3.10 and V2 function. All logs in deployment center doesn’t show any error.

My requirement function is : azure-functions

openai[datalib]==0.28
azure-search-documents ==11.4.0b9
azure-storage-blob==12.14.1
cffi
markdown
pymongo
python-jose
six
tiktoken
msal

I had the same issue and found the actual error by opening MyAzureFunction/Monitoring/Log Stream/Filesystem Logs and deploying the function.

I saw an error that imports were broken even though VS code said deployment was “successful” and function did not appear. Fixed this error and now function appears.

EDIT:

Added more code and it no longer shows any other errors in that log stream and function does not appear…

I found the actual actual error by setting up WSL in VS code and running the function there. It immediately threw the error which azure eats up. It was a keras model which works in windows but doesn’t work in linux, I just re-saved this model using WSL, tested locally, and now functions appear in Azure.

Azure should just throw these errors instead of silencing them and saying that the deployment is successful…

TLDR: Use WSL to test your function locally

@niraj-rel are you still facing this issue? If yes, could you please create a new github issue or a support ticket?https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

We’ll need to see some more logs to check what’s causing this error.

Hello Gavin, Yes this issue is still there. I’ve raised a support ticket with Azure. They are looking into this. There’s some issue with the Github Deployment for Azure Functions. For some reason its not installing the libraries from requirements.txt. I found this from logs because of the import issues. The code works locally well. If I deploy the code from locally to Azure Function that works, but the Github Deployment has some issue.

Will this issue ever be fixed by azure? I tried deploying the function app 15 times yesterday and its not visible on portal

I face the same issue. The code runs locally but the func app is not visible on Azure Cloud. I’ve the same structure in my another function app and that code runs in Azure but when I created a new one with the same code base it doesnt

Hi @niraj-rel I am from MSFT and deployed lot of function apps until this point. The error’s you are facing is common and frustrating. One reason I found is difference between the environment in the azure function app cloud to the local. So the trick is always to write everything in the function basis.

  1. Convert everything to function based in the code. Avoid single line codes outside function app
  2. Make sure every function has try catch block, so incase of error also function will be visible
  3. This sounds childish but keep your import statements also in the try catch block. As lot of times this error shows up because of the package and dependencies in the cloud. Have Luck

@pdthummar that has worked, thank you!

As a result of this compatibility issue, the worker is failing to index functions with below error, due to this, functions aren’t visible in the portal.

Please can you advise how and where we can look up that failures?

@pdthummar Thank you, that seems to work now!

I used the VSCode-created blueprint.py unmodified; perhaps it would be good for the auto-generated example to not cause such errors. It did ask for both the blueprint filename and the new function name, so that’s arguably on me, but perhaps the sample could call the azure.functions.Blueprint object (and the decorator) FILE_bp or something like that just to minimize the chance of conflict.

In any case, indicating some kind of error during the deployment process would be great.

Also, both app.register_functions() and app.register_blueprint() seem to work; is there a different/preference?

Thanks again!

Adding a comment to this ticket as well since this one is open. (#1262 is closed)

All I had in my requirements.txt file was azure-functions and I still saw this.

Saw what, exactly? The issue in #1262 can have many causes. Do you built locally and do a ZIP deployment? Do you perform a remote build? I have a special repo with reproducible steps for the issue of ‘Functions not showing in Azure Portal’, and they all have the same issue: there is an unhandled exception raised in the root of your script or imports. The reason may vary:

  • You do a ZIP deployment, but perform the pip install step on a Windows machine, while deploying to a Linux machine and one of your dependencies was specifically downloaded for Windows;
  • You have a relative import that doesn’t work;
  • You get an environment variable that doesn’t exists in the root of your .py file with my_var = os.environ('MYVAR') (this will raise a KeyError if MYVAR doesn’t exists);

Etc. There are countless ways to induce this behavior and the only thing Microsoft has to do is to propagate the exception raised to Application Insight so we can actually see what is wrong.

If you have no idea what is wrong: pull everything in the scope of your function method. So, rather than doing this:

import azure.functions as func
import my_package
import os

myvar = os.environ("MYVAR")

app = func.FunctionApp()

@app.function_name(name="HttpExample")
@app.route(route="hello")
def test_function(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("HttpExample function processed a request!")

Try this:

import azure.functions as func

app = func.FunctionApp()

@app.function_name(name="HttpExample")
@app.route(route="hello")
def test_function(req: func.HttpRequest) -> func.HttpResponse:
    import my_package
    import os

    myvar = os.environ("MYVAR")
    return func.HttpResponse("HttpExample function processed a request!")

Now call your function and see what exception you get. If you don’t get an exception, then at least you can move back the lines of code one by one to pinpoint which one is causing issues.