azure-functions-python-worker icon indicating copy to clipboard operation
azure-functions-python-worker copied to clipboard

Azure function python v2 with external packages HTTP Trigger not visible in Azure Portal after deployment

Open SiddheshDesai06 opened this issue 2 years ago • 111 comments

Refer this SO Thread and my answer - https://stackoverflow.com/questions/76458717/why-is-the-functions-runtime-not-finding-my-functions-when-i-import-certain-pack/76463210?noredirect=1#> The Azure python Function with V2 programming model including external packages and imports in function_app.py works locally, But when I deploy it in Azure the Function Trigger is not visible. If I deploy default HTTP Trigger with python v2 programming model, The trigger is visible after deployment. But not when i add custom imports in the function_app.py and requirements.txt. Refer this image - https://i.imgur.com/CjCnsY8.png but the function files are visible in app files like here- https://i.imgur.com/R3SZWcW.png . I tried the deployment with App service plan and consumption plan both, Still no luck. I also added AzureWebJobsFeatureFlags:EnableWorkerIndexing settings, I also tried to deploy this function as zip using azure cli zip command with required settings to deploy function as zip, I also tried to deploy it with function core tools func azure functionapp publish command and also via VS code still no luck.

Investigative information

Please provide the following:
  • Timestamp:
  • Function App name: siliconfunc311
  • Function name(s) (as appropriate): Http trigger pythonv2
  • Core Tools version:4.0.5148

Repro steps

Provide the steps required to reproduce the problem:

Refer this SO thread and my answer- https://stackoverflow.com/questions/76458717/why-is-the-functions-runtime-not-finding-my-functions-when-i-import-certain-pack/76463210?noredirect=1#comment134830419_76463210

Expected behavior

Provide a description of the expected behavior.

after deployment HTTP trigger should be visible in Azure portal

Actual behavior

Provide a description of the actual behavior observed.

Function trigger is not visible in Functions section of Function tab but files are visible in app files

Known workarounds

Provide a description of any known workarounds.

Contents of the requirements.txt file:

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

numpy

pandas

opencv-python-headless

librosa

torch

torchaudio

torch-audiomentations

torchvision

azure-functions

Related information

Provide any related information
  • Links to source

https://stackoverflow.com/questions/76458717/why-is-the-functions-runtime-not-finding-my-functions-when-i-import-certain-pack/76463210?noredirect=1#comment134830419_76463210

# function_app.py

import logging
import azure.functions as func
import numpy as np
import pandas as pd
import cv2
import librosa
import torch
import torchaudio
import torch_audiomentations
import torchvision
from azure.functions import HttpRequest


app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)



@app.route(route="HttpTrigger")
def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    #code block with imported packages 
    arr = np.array([1, 2, 3])
    df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
    image = cv2.imread('Screenshot (1).png')
    audio_data, sample_rate = librosa.load('sample.wav.mp3')
    tensor = torch.tensor([1, 2, 3])
    transformed_tensor = torch_audiomentations.PitchShift(sample_rate=sample_rate, p=1.0)
    torchvision.transforms.ToTensor()(image)

    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get('name')

    if name:
        return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

SiddheshDesai06 avatar Jun 13 '23 18:06 SiddheshDesai06

Did this problem start recently?

I had a v2 programming function app deployed that was working fine, however last night i made some changes and I can no longer see the functions. I've tried everything and attempting to revert to the old code but I can't seem to see what is different.

Maybe Azure have made some changes that have impacted us?

VirajVaitha123 avatar Jun 14 '23 13:06 VirajVaitha123

@VirajVaitha123 thanks for informing and can you share the function name,region,invocationid etc. So I can investigate same at our end.

bhagyshricompany avatar Jun 14 '23 15:06 bhagyshricompany

I'm the author of the SO question and wanted to add that I found this issue only applies when deploying to a consumption plan. When I deploy to a dedicated app service plan, the functions load.

cghgreg avatar Jun 14 '23 19:06 cghgreg

@VirajVaitha123 thanks for informing and can you share the function name,region,invocationid etc. So I can investigate same at our end.

Sure

function name : scryptifyf1 region: north europe, invocationid: (I can't find this)..

VirajVaitha123 avatar Jun 14 '23 21:06 VirajVaitha123

@VirajVaitha123 Thanks for input I will update once check

bhagyshricompany avatar Jun 15 '23 08:06 bhagyshricompany

Thanks for looking into this.

Do we know if this problem is one multiple people are facing, and there is nothing we can do to deploy with Python v2 programming model?

VirajVaitha123 avatar Jun 15 '23 18:06 VirajVaitha123

@VirajVaitha123 pls share the start time and end time

bhagyshricompany avatar Jun 19 '23 08:06 bhagyshricompany

I have been experiencing the exact same issue for over a week - I have tried the different deployment methods, as well as deleting and recreating the Function App and App Service Plan.

MT-- avatar Jun 19 '23 16:06 MT--

Only workaround I know is to switch to the V1 programming model.

cghgreg avatar Jun 19 '23 16:06 cghgreg

@gavin-aguiar pls comment

bhagyshricompany avatar Jun 19 '23 16:06 bhagyshricompany

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Jun 24 '23 12:06 ghost

I'm experiencing a similar issue but with two differences:

  1. I'm using a timer trigger rather than an HTTP trigger
  2. I'm getting the error '1 found, 0 loaded" in my logging as opposed to the error displayed in the SO post.

One additional thing I've noticed when I've probed around in my portal is that Genie is reporting the following error:

Worker failed to index functions
Result: Failure Exception: ImportError: cannot import name '_imaging' from 'PIL' (/home/site/wwwroot/.python_packages/lib/site-packages/PIL/init.py). Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py', line 338, in _handle__functions_metadata_request fx_metadata_results = self.index_functions(function_path) File '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/dispatcher.py', line 607, in index_functions indexed_functions = loader.index_function_app(function_path) File '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 48, in call raise extend_exception_message(e, message) File '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/utils/wrappers.py', line 44, in call return func(*args, **kwargs) File '/azure-functions-host/workers/python/3.10/LINUX/X64/azure_functions_worker/loader.py', line 151, in index_function_app imported_module = importlib.import_module(module_name) File '/usr/local/lib/python3.10/importlib/init.py', line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File '', line 1050, in _gcd_import File '', line 1027, in _find_and_load File '', line 1006, in _find_and_load_unlocked File '', line 688, in _load_unlocked File '', line 883, in exec_module File '', line 241, in _call_with_frames_removed File '/home/site/wwwroot/function_app.py', line 2, in from core.data.training_image_filestore import TrainingImageFilestore File '/home/site/wwwroot/core/data/training_image_filestore.py', line 1, in from PIL import Image File '/home/site/wwwroot/.python_packages/lib/site-packages/PIL/Image.py', line 103, in from . import _imaging as core

That is followed by this error:

No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

The key thing that strikes me as odd here is that it's failing to import the package from /home/site/wwwroot/.python_pacakages/...

Looking in my storage account, the reason it's failing is obvious - there's no .python_packages file in wwwroot.

After liaising with the OP of this github issue on my own SO post, we're using identical Azure Pipeline YAML definitions. The key thing is we're both running from zip packages, rather than deploying the code directly so I wouldn't expect there to be anything in wwwroot.

Since my function_app.py file imports a load of custom packages (which in turn import PIL), and does so before declaring the function, my thinking is that the imports are erroring about because Python should be looking for them in the package but is actually looking for them in the site root (working directory). Since they aren't there, it errors out so never makes it as far as far as the function app declaration.

Just a guess but given the errors it would make sense.

What to do about that, however, I don't know!

For now it looks like the two workarounds are:

  1. Downgrade to v1 programming model
  2. Swap to a dedicated ASP rather than consumption plan

I followed the first of these options and this resolved my issue.

Laura10101 avatar Jun 27 '23 07:06 Laura10101

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Jul 01 '23 12:07 ghost

I'm facing the same challenge over here using python. The Function HTTP triggers are not visible in Functions section of Function tab but files are visible in App files.

Otimkev avatar Jul 01 '23 19:07 Otimkev

@bhagyshricompany Can you take a look at this issue? I see multiple customers facing this issue?

sid24desai avatar Jul 03 '23 06:07 sid24desai

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

ghost avatar Jul 07 '23 09:07 ghost

This is still an issue, I am seeing it happen on occasion. As of yet cannot figure out a pattern for why it happens or how to fix it.

MikeJerred avatar Jul 21 '23 08:07 MikeJerred

@bhagyshricompany Can you check this issue? Looks like its a bug, Multiple customers are reporting it?

SiddheshDesai06 avatar Jul 21 '23 09:07 SiddheshDesai06

Can you reproduce it on your end with the code in the question? with python function v2? The trigger won't be visible in the portal despite all the solutions in v2. It works in v1

SiddheshDesai06 avatar Jul 21 '23 09:07 SiddheshDesai06

Surprisingly what worked for me, was creating a new venv, installing pip requirements and testing the app still works.

Sometimes, the Azure Functions Compute may find a conflict with packages too, and you won't even know. So making certain packages == version in requirements can help.

Finally, don't just export your requirements.txt. As this returns a huge list of requirements. write the names as you install them.

It's surprising azure don't show an error message, instead just hides the functions in the UI.

VirajVaitha123 avatar Jul 21 '23 09:07 VirajVaitha123

What I am seeing is this log:

[Information]   1 functions found
[Information]   0 functions loaded

And the app function doesn't appear in the functions tab, but the file do appear under app files. The exact same python code deployed to a different environment is working fine.

MikeJerred avatar Jul 21 '23 10:07 MikeJerred

I had a similar issue, my Azure Function worked perfectly in local testing. Deployment was succesful, but no triggers were shown. I could not find any logs showing any errors at all.

I downgraded to the v1 python worker based on the discussion in this thread. Using the v1 worker, the trigger was created, but I could see it generated an error when trying to import the psycopg2 package, changing the requirements.txt to use psycopg2-binary fixed this issue. Retrying the v2 python worker using the psycopg2-binary package worked and the trigger showed up succesfully. I think this is similar to the issue @VirajVaitha123 was experiencing.

It appears the v2 worker doesn't show an error message and doesn't create the trigger where the v1 worker does.

mjvanderboon avatar Jul 27 '23 14:07 mjvanderboon

I am having the same issue with my functions no showing/loading. Everything works locally & debugging but when pipelines or vscode deploys to the function it succeeds but never shows any functions.

duncanldavis avatar Aug 04 '23 06:08 duncanldavis

I am also experiencing the issue. Local running works fine but deployment using VSCode and the CLI result in no functions being shown in the Azure Portal with no error messages being thrown.

robmitchellzone avatar Aug 09 '23 17:08 robmitchellzone

I am experiencing this issue as well. I have a python function app with which I would like to use the v2 programming model. Tests succeed locally. However, when I deploy my code to the function app with the cli, the build succeeds but no triggers are listed (there is one ServiceBusTrigger in the app). I narrowed it down to the single import of my own code that I have in function_app.py (from game_ingestor.core.ingest import GameIngestor ). If I remove the import (as a result the trigger does nothing with the messages it receives), and deploy the code with the cli the trigger is visible. I tried changing the code to adopt the V1 model with the imports. Under the V1 model, my deployments with the cli behave as expected, with the single trigger listed.

paulducks avatar Aug 11 '23 17:08 paulducks

I am also experiencing the issue. 🙅

mateusztylec avatar Sep 04 '23 05:09 mateusztylec

Also experiencing this issue. Like others, the logs only show this:

[Information] 1 functions found [Information] 0 functions loaded

The files are present, deployments all succeed, and there are no errors in the logs. Running absolutely fine in another region in a function with same code, build steps & app config values.

Running on a P1:V3 app plan.

riosengineer avatar Sep 06 '23 14:09 riosengineer

I was able to resolve this issue. I had to remove any code in my function_app.py file and blueprint.py file that was above my function definition, apart from imports and initializing the FunctionApp or Blueprint objects.

robmitchellzone avatar Sep 06 '23 14:09 robmitchellzone

I an facing the exact same issue. My function works in V1 version, but with V2 it works in local, but cannot see the function when deployed. I am deploying from VSCode to Serverless. @robmitchellzone Will you please give us a bit more details of the fix that worked for you.

shahztechfarm avatar Sep 07 '23 11:09 shahztechfarm

@shahztechfarm, I had variables declared above my function definition in my blueprint.py file. Moving those statements to within the function allowed Azure to detect the function when deployed to the cloud.

robmitchellzone avatar Sep 07 '23 12:09 robmitchellzone