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

[BUG] AsgiFunctionApp is missing BindingApi and SettingsApi mixins #1422

Closed
mortendaehli opened this issue Feb 5, 2024 · 4 comments · Fixed by Azure/azure-functions-python-library#209
Assignees
Labels
pending-release Fixed but pending docker image, runtime or core tools release.

Comments

@mortendaehli
Copy link

mortendaehli commented Feb 5, 2024

Investigative information

  • Timestamp: 2024-02-05T08:28:51.887Z
  • Core Tools version: 4.0.5455

Repro steps

  1. Create Azure Functions Python V2 docker template
  2. Create AsgiFunctionApp using FastAPI
  3. Add any BindingApi functions such as queue_output
  4. Run the application in Docker (need to install Core tools and run in verbose to get the actual Exception. Without it, it fails silently)

Expected behavior

I should be able to add BindingApi and SettingsApi such as queue output, function name, etc. to my application while running FastAPI.

Actual behavior

No functions are loaded when running in Docker.

If I add the Core Tools and run --verbose:

[2024-02-05T08:29:00.675Z] Worker failed to index functions
[2024-02-05T08:29:00.676Z] Result: Failure
[2024-02-05T08:29:00.677Z] Exception: AttributeError: 'AsgiFunctionApp' object has no attribute 'queue_output'
[2024-02-05T08:29:00.677Z] Stack:   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 345, in _handle__functions_metadata_request
[2024-02-05T08:29:00.677Z]     fx_metadata_results = self.index_functions(function_path)
[2024-02-05T08:29:00.677Z]                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/dispatcher.py", line 617, in index_functions
[2024-02-05T08:29:00.677Z]     indexed_functions = loader.index_function_app(function_path)
[2024-02-05T08:29:00.677Z]                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 44, in call
[2024-02-05T08:29:00.677Z]     return func(*args, **kwargs)
[2024-02-05T08:29:00.677Z]            ^^^^^^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z]   File "/usr/lib/azure-functions-core-tools-4/workers/python/3.11/LINUX/X64/azure_functions_worker/loader.py", line 214, in index_function_app
[2024-02-05T08:29:00.677Z]     imported_module = importlib.import_module(module_name)
[2024-02-05T08:29:00.677Z]                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z]   File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
[2024-02-05T08:29:00.677Z]     return _bootstrap._gcd_import(name[level:], package, level)
[2024-02-05T08:29:00.677Z]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap_external>", line 940, in exec_module
[2024-02-05T08:29:00.677Z]   File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
[2024-02-05T08:29:00.677Z]   File "/home/site/wwwroot/function_app.py", line 35, in <module>
[2024-02-05T08:29:00.677Z]     ingestion.app_factory(app)
[2024-02-05T08:29:00.677Z]   File "/home/site/wwwroot/src/data_hub/ingestion.py", line 22, in app_factory
[2024-02-05T08:29:00.677Z]     @app.queue_output(arg_name="msg", queue_name="model-data-ingestion-queue", connection="AzureWebJobsStorage")  # type: ignore[misc]
[2024-02-05T08:29:00.677Z]      ^^^^^^^^^^^^^^^^
[2024-02-05T08:29:00.677Z] .
[2024-02-05T08:29:00.683Z] 0 functions found (Worker)
[2024-02-05T08:29:00.699Z] 0 functions loaded

Known workarounds

This monkey patch works:

class FastAPIFunctionApp(func.AsgiFunctionApp, func.BindingApi, func.SettingsApi):
    """
    Adding missing BindingApi and SettingsApi to the AsgiFunctionApp
    """
    pass

Contents of the requirements.txt file:

azure-functions
fastapi

Related information

  • BindingApi in general
  • SettingsApi in general
@YunchuWang
Copy link
Member

thanks for reporting this issue! a pr is out for fixing this and will be included in next release.

@YunchuWang YunchuWang added the pending-release Fixed but pending docker image, runtime or core tools release. label Mar 8, 2024
@mortendaehli
Copy link
Author

thanks for reporting this issue! a pr is out for fixing this and will be included in next release.

Thanks a lot! This is much appreciated!

@DCMattyG
Copy link

Great to see this! Will this finally allow the default name of "http_app_func" to be modified for things like FastAPI apps?

@seidnerj
Copy link

Any news on when will this fix be released? thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-release Fixed but pending docker image, runtime or core tools release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants