Skip to content

[Bug][BC break][Router] Multiple routes to same path with different methods #29410

Closed
@peterrehm

Description

@peterrehm

Symfony version(s) affected: 4.1.8

Description
I am upgrading an older app from Symfony 3.4 to Symfony 4 and suddenly I have some tests dailing due to unreachable routes.

I have the following two routes configured:

api_customers_contactpersons_contactperson_create:
  path:     /api/customers/{customerId}/contactpersons
  defaults: { _controller: 'App\Controller\Api\CustomersController::createContactPersonAction' }
  methods:  [POST]

api_customers_contactpersons:
  path:     /api/customers/{customerId}/contactpersons/
  defaults: { _controller: 'App\Controller\Api\CustomersController::customerContactPersonsAction' }
  methods:  [GET]

They are properly recognized according to the debug:router command:

 --------------------------------------------------------------------- ---------- -------- ------ -------------------------------------------------------------------------------------------------------------
  Name                                                                  Method     Scheme   Host   Path
 --------------------------------------------------------------------- ---------- -------- ------ -------------------------------------------------------------------------------------------------------------
 api_customers_contactpersons_contactperson_create                POST       ANY      ANY    /api/customers/{customerId}/contactpersons
 api_customers_contactpersons                                     GET        ANY      ANY    /api/customers/{customerId}/contactpersons/

Only the first route works. If I change the order the other route works.

With this order I am geeting the error

request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "GET /api/customers/4/contactpersons": Method Not Allowed (Allow: POST)"

With the GET request as the first order the POST request fails as well, it just mentions the route as not found.

Does anyone have an idea what the reason could be? It worked fine in with previous Symfony version.

How to reproduce
Once feedback is provided I could set up a sample app.

Possible Solution

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions