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] Using modern python types instead of typing.XXX with queue output binding #1176

Closed
kummerer94 opened this issue Feb 17, 2023 · 8 comments
Assignees

Comments

@kummerer94
Copy link

kummerer94 commented Feb 17, 2023

Investigative information

Hi, I think the queue output binding does not yet play nice with the modern type declarations that are part of newer python models.

  • Core Tools Version: 4.0.4915 (64-bit)
  • Function Runtime Version: 4.14.0.19631

Repro steps

I tried using func.Out[list[str]] for my output binding instead of func.Out[typing.List[str]] and it gave me this error:

[2023-02-17T10:32:04.022Z] Worker failed to index functions
[2023-02-17T10:32:04.023Z] Result: Failure
Exception: TypeError: issubclass() arg 1 must be a class
Stack:   File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure_functions_worker\dispatcher.py", line 332, in _handle__functions_metadata_request
    fx_metadata_results = loader.process_indexed_function(
  File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure_functions_worker\loader.py", line 69, in process_indexed_function
    function_info = functions_registry.add_indexed_function(
  File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure_functions_worker\functions.py", line 405, in add_indexed_function
    input_types, output_types = self.validate_function_params(params,
  File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure_functions_worker\functions.py", line 228, in validate_function_params
    checks_out = bindings_utils.check_output_type_annotation(
  File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure_functions_worker\bindings\meta.py", line 50, in check_output_type_annotation
    return binding.check_output_type_annotation(pytype)
  File "C:\Users\ME\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\workers\python\3.10\WINDOWS\X64\azure\functions\queue.py", line 104, in check_output_type_annotation
    or (isinstance(pytype, type) and issubclass(pytype, valid_types))
  File "C:\Program Files\Python310\lib\abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)

I am using the new python programming model v2.

To reproduce this, I am using the following function:

@bp.function_name(name="QueueOutputBindingFunction")
@bp.route(route="QueueOutputBindingFunction")
@bp.queue_output(
    arg_name="out", queue_name="myqueue", connection="AzureStorageQueuesConnectionString"
)
def test_binding(req: func.HttpRequest, out: func.Out[list[str]]) -> func.HttpResponse:
    out.set(["something"])
    return func.HttpResponse(status_code=202)

Known workarounds

Right now, the workaround is to use the List class provided by the typing module. But more and more people are moving away from using the typing module because it is not necessary anymore.

For now, it would also be great to make this error more descriptive as it took me some time to figure out what was going on.

@bhagyshricompany bhagyshricompany self-assigned this Feb 20, 2023
@bhagyshricompany
Copy link

Thanks for update will update on this asap.

@bhagyshricompany
Copy link

bhagyshricompany commented Feb 20, 2023

@bp instance for which function instance created? is it from flask import Blueprint
or some thing else pls specify

@kummerer94
Copy link
Author

Ah, sorry, yes. This is the blueprint bp = func.Blueprint() but I think you will also see the problem with @app instead of @bp.

@bhagyshricompany
Copy link

bhagyshricompany commented Feb 20, 2023

can you share zip file for the same
Thanks

@bhagyshricompany
Copy link

from your error msg it suggest that the problem is with the issubclass() method, which expects the first argument to be a class. This indicates that the list class is not being recognized as a valid type for the output binding.

To fix this, you can try using typing.List[str] instead of list[str] for the output binding type annotation. This should resolve the error and allow you to use the correct type annotation for the output binding.

Here's an example of how to use typing.List[str] for the output binding type annotation:
import logging
import azure.functions as func
import typing

def main(req: func.HttpRequest, outputQueueItem: func.Out[typing.List[str]]) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')

names = ["demo1", "demo2", "demo3"]
outputQueueItem.set(names)

return func.HttpResponse(f"Processed {len(names)} names.")

I hope this helps and Meanwhile you can share your solution with zip file.

@bhagyshricompany
Copy link

@madhankumar1984 pls update with your file.
Thanks

@vrdmr
Copy link
Member

vrdmr commented Feb 22, 2023

It is related to #1034 - Needs investigation.

@gavin-aguiar
Copy link
Contributor

@kummerer94 Currently the python worker does not support type hinting. We are working on getting that support in. Updates on this will be tracked in #1034

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

4 participants