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

UmbracoApiController routing does not work if the route is the same for POST and GET requests #16434

Open
lommijuho opened this issue May 29, 2024 · 4 comments

Comments

@lommijuho
Copy link

lommijuho commented May 29, 2024

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

13.2.2

Bug summary

When I upgraded from U10.5.1 to U13.2.2 I faced an issue that broke my UmbracoApiController routing. When I make a GET request to an endpoint that shares the route with a POST endpoint, the GET request returns a 404. If I use unique routes for each request method, everything seems to be working correctly.

Specifics

No response

Steps to reproduce

Create a fresh Umbraco project and add 2 controllers with the same route but different methods e.g.:

[ApiController]
[Route("api/")]
public class ProductManagementApiController : UmbracoApiController
{

    [HttpPost("test")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [Consumes(MediaTypeNames.Application.Json)]
    public IActionResult CreateBrandProduct()
    {
        return Ok("OK POST");
    }

    [HttpGet("test")]
    [ProducesResponseType(StatusCodes.Status200OK)]
    public IActionResult GetAllBrandProducts()
    {

        return Ok("OK GET");
    }
}

Making a POST request works, but GET request request returns 404.
I was able to follow the issue and found out that ApiVersionMatcherPolicy.ApplyAsync() scores both of my endpoint candidates to a negative value and therefore makes both of them invalid. I'm not sure if this is the real issue but this could somehow be related to the problem. When removing ApiVersionMatcherPolicy from builder.Services, both endpoints worked correctly.

Expected result / actual result

I assume that in this situation both endpoints should work normally, because the request method is different.


This item has been added to our backlog AB#42384

Copy link

Hi there @lommijuho!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

  • We'll assess whether this issue relates to something that has already been fixed in a later version of the release that it has been raised for.
  • If it's a bug, is it related to a release that we are actively supporting or is it related to a release that's in the end-of-life or security-only phase?
  • We'll replicate the issue to ensure that the problem is as described.
  • We'll decide whether the behavior is an issue or if the behavior is intended.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@NguyenThuyLan
Copy link
Contributor

NguyenThuyLan commented Jul 18, 2024

I can reproduce it on both v13.4.1, v14.1.1, v12 and does not happen on v11.
I tried with another API Controller without UmbracoApiController. And it has the same error as in the issue.
I think Umbraco's source code has affected something here.
The temporary solution is not to use Consumes Attribute (Cause it works when not using Consumes) or change the path of HttpGet request

@NguyenThuyLan NguyenThuyLan added state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks status/regression affected/v12 labels Jul 18, 2024
@bergmania
Copy link
Member

Hi @lommijuho ..

After looking into this, it seems like a unintended side-effect, that has occurred since the introduction of the delivery api and especially the API versioning dependency (like you found).

In the example you give, where you only have a ConsumesAttribute on only one endpoint, leads to the two endpoints having diffrent score when it hits the ApiVersionMatcherPolicy. That implementation is from an external dependency, but that only returns one endpoint with a positive score. (What it consider the best match).

If you do not have this ConsumesAttribute or have it on both endpoints, they will have same score, when it execute ApiVersionMatcherPolicy, and both will be considered in later matcher policies.

I'm afraid the only real solution to this, is to report it on thier repository, as the same happens on plain asp.net core controllers.

I think the smoking gun is this code https://github.com/dotnet/aspnet-api-versioning/blob/main/src/AspNetCore/WebApi/src/Asp.Versioning.Http/Routing/ApiVersionMatcherPolicy.cs#L403-L405

@bergmania bergmania removed the state/sprint-candidate We're trying to get this in a sprint at HQ in the next few weeks label Aug 6, 2024
@bergmania
Copy link
Member

I have created an minimal setup issue on the dependency's repository: dotnet/aspnet-api-versioning#1101

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

3 participants