Azure / Azure/azure-functions-host

Azure Function v3: Route-Parameter overrides Request-Body

Open
#7,277 6 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

When using Azure Function v3, I run into some strange behaviour.

I have a custom Request-Type:

```csharp
public class MyRequest
{
public Guid Id { get; set; }
public string Name { get; set;}
}
```

My Azure Function likes something like:

```csharp
[FunctionName(nameof(MyRequestFunction))]
public async Task UpdateRoleAsync(
[HttpTrigger(AuthorizationLevel.Function, HttpMethodNames.Put, Route = "someapi/{id}")]
MyRequest input, Guid id)
{

}
```

I send a request to my function with "someapi/2cb0fce7-1588-42fc-9657-ad36f6be1f09" and the following body:

```json
{
"id": "b8a29105-81da-41e6-bc9e-0f83138f754a",
"name": "Testname"
}
```

During debuggung i noticed that the id from the route (2cb0fce7-1588-42fc-9657-ad36f6be1f09) was written to the id-property of the MyRequest instance and overwrites the original value (b8a29105-81da-41e6-bc9e-0f83138f754a).

If the name of the Route-Parameter is changed from id to myRouteResponseId everything works fine.

How can I prevent the auto-overwritting of Properties with the same name?

Thanks in advance!

-----
Original Post: https://github.com/Azure/Azure-Functions/issues/1872#issue-848224663

Contributor guide

Open the contributing guide

Research direction

Reproduce the Azure Function v3 binding behavior using the MyRequest class, the someapi/{id} route, and the conflicting route and JSON-body IDs shown in the issue. Start by examining how HTTP trigger route parameters are bound alongside the request body. Done means establishing whether the overwrite is expected and documenting or implementing a supported way to prevent it.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.