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] FunctionMetadataGenerator does not assign cardinality as many for IEnumerable<> scenarios #1204

Closed
2 tasks done
surgupta-msft opened this issue Dec 1, 2022 · 3 comments · Fixed by #1271
Closed
2 tasks done

Comments

@surgupta-msft
Copy link
Contributor

surgupta-msft commented Dec 1, 2022

Investigate and fix in FunctionMetadataGenerator and Source Generation why Cardinality is not assigned to Many when function binds to IEnumerable<> type. This stops the collection support even when it is enabled by the extension - here as Host uses the value of cardinality to assign array type.

Sample function for repro -

[Function("Function")]
public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req,
    [BlobInput("input-container", Connection = "AzureWebJobsStorage")] IEnumerable<string> blobs)
}

Current output function.metadata -

  "bindings": [
      {
        "name": "data",
        "type": "blob",
        "direction": "In",
        "blobPath": "input-container",
        "connection": "AzureWebJobsStorage"
       // "cardinality": "Many" --> Expected here
      },
      {
        "name": "$return",
        "type": "http",
        "direction": "Out"
      }
    ]
@satvu
Copy link
Member

satvu commented Dec 1, 2022

From a quick skim it seems we have handling and tests cases for Cardinality with EventHubs bindings but not Blobs ... from offline discussion we may also need handling for CosmosDB.

References that may help with investigation/fix:

  1. What is officially supported according to storage extension docs.
  2. We have the test case for this scenario with EventHubs bindings here which is run in the test matrix here.

@surgupta-msft
Copy link
Contributor Author

Found some information in blob extension documentation. This can probably be the list of scenarios expected to be supported by this extension.

image

Another thing I found which may be helpful with the investigation here is isBatched = true for EventHubTrigger but not for KafkaTrigger and ServiceBus and they all implement ISupportCardinality. This can be the reason for why it works for only EventHubs

  1. EventHubTriggerAttribute
 public sealed class EventHubTriggerAttribute : TriggerBindingAttribute, ISupportCardinality
    {
        // Batch by default
        private bool _isBatched = true;
  1. KafkaTriggerAttribute
 public sealed class KafkaTriggerAttribute : TriggerBindingAttribute, ISupportCardinality
    {
        private bool _isBatched = false;

@liliankasem
Copy link
Member

liliankasem commented Jan 6, 2023

I think the addition of the IsBatched attribute is definitely the key here, we don't use it at all for blob but it is implemented for EventHubs, ServiceBus, and Kafka. Looking at the FunctionMetadataGenerator we can see that cardinality is only set if IsBatched is true (code).

This implies that there's isn't a bug with FunctionMetadataGenerator and the solution here might just be to add an IsBatched attribute for the blob input and trigger attributes.

Edit: will also need to update this to support Reference type

@ghost ghost locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.