Azure / Azure/azure-functions-host

Unable to name HTTP Trigger paramater 'query'

Open
#5,378 8 comments 0 reactions 0 assignees View on GitHub
needs-investigation
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

Hi, I've ran into an issue when naming a function paramater

> query

By doing this is causes the function to fail to bind. I've created a barebones example at the bottom of this post, not sure if this is expected behaviour, please let me know :)

I've currently only tested this with **GET** requests, additionally binding also fails with non-complex types.

#### Investigative information

- Function App version (1.0 or 2.0): 2.0
- Function App name: TestBugFunc
- Function name(s) (as appropriate): Function1
- Function Runetime Version: 2.0.12888.0
- Function Core Tools Version: 2.7.1948

#### Repro steps

Example:

1. Create HTTP trigger function app in 2.0
2. Add route binding for a url parameter to bind to a object with related parameter name
3. Call object paramater name query
4. Run function and create a valid GET request

#### Expected behavior

During startup, all function bindings to succeed.

GET: api/Function1/3123
After I perform the request I expect the function to be able to pick this up and handle the request.
#### Actual behavior

During **startup**: Binding fails with error

```
[12/12/2019 16:12:55] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'query' to type 'TestBugFunc.Function1+FooQuery'.
[12/12/2019 16:12:55] Error indexing method 'Function1'
[12/12/2019 16:12:55] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'query' to type 'TestBugFunc.Function1+FooQuery'.
[12/12/2019 16:12:55] Function 'Function1' failed indexing and will be disabled.
[12/12/2019 16:12:55] 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.).
[12/12/2019 16:12:55] Initializing function HTTP routes
[12/12/2019 16:12:55] Mapped function route 'api/Function1/{id}' [get] to 'Function1'
[12/12/2019 16:12:55]
[12/12/2019 16:12:55] Host initialized (456ms)
[12/12/2019 16:12:55] Host started (462ms)
[12/12/2019 16:12:55] Job host started
[12/12/2019 16:12:55] The 'Function1' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Function1'. Microsoft.Azure.WebJobs.Host: Can't bind parameter 'query' to type 'TestBugFunc.Function1+FooQuery'.
```

During **runtime** call: Function returns a 500 error and throws a console error with below, probably due to failed binding.

```
An unhandled host error has occurred.
[12/12/2019 16:01:25] Microsoft.Azure.WebJobs.Host: 'Function1' can't be invoked from Azure WebJobs SDK. Is it missing Azure WebJobs SDK attributes?.
```

#### Known workarounds

Renaming parameter

#### C# Function code(Test example that throws exception)

Source

```csharp
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;

namespace TestBugFunc
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "Function1/{id}")] FooQuery query)
{
return new OkResult();
}

public class FooQuery
{
public string Id { get; set; }
}
}
}

```

Thanks!

Contributor guide

Open the contributing guide

Research direction

Start with the C# Function1 example and investigate HTTP trigger binding and function indexing for a parameter named query. Reproduce the GET request using the supplied route, then verify that startup binding succeeds and the function can be invoked without the reported 500 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.