Nest: A method handler is interfering into another handler with same name in another controller.

Created on 28 Jul 2019  路  6Comments  路  Source: nestjs/nest

Bug Report

Current behavior

I had two controllers into two differnt folders and differnt modules, Both of them has a method with same create name.

/admin/entity.controller.ts

    @Controller("admin")
    export class EntityController{
        @Post()
        public async create(@Request() request: any): Promise<List> {
            console.log("request", request) // Logs the Body {"name": "test"} instead of request.
        }
    }

/user/entity.ontroller.ts

    @Controller("user")
    export class EntityController{
        @Post()
        public async create(@Body() entity: Entity) {
            console.log("entity", entity) // logs the body {"name": "test"}
        }
    }

When I do post the following in both routes: {"name": "test"},

curl -X POST http://localhost:3000/admin/ -d '{"name":"test"}'

curl -X POST http://localhost:3000/user/ -d '{"name":"test"}'

It happens that admin create() method logs the body part, not the requests as expected.

It seems to be that the definition of the user controller is interfering into the admin controller and making it to do not work properly.

Environment

  • Nest version: 6.0.0
  • Node version: v10.15.1
  • Platform: Windows 10
core done 馃憦 type

All 6 comments

Please, provide a minimal repository which reproduces your issue.

same issue
@kamilmysliwiec there is a repo
https://github.com/xyunsh/samenamed

http://localhost:3000/user1/details controller named UserController -> /user1/details
http://localhost:3000/user2/details controller named UserController -> get error
moduleb's UserController not work.

http://localhost:3000/usera/details controller named UseraController-> /usera/details
http://localhost:3000/userb/details controller named UserbController-> /userb/details
modulea & moudleb's controllers both work well.

Thanks! I'll push fix asap

Fixed in 6.6.0 :)

@kamilmysliwiec @daniel-dia The problem is only partially fixed. There is a very similar bug with global pipes. When 2 controllers with the same name and method are used public async transform(value: any, metadata: ArgumentMetadata) method of pipes receives incorrect ArgumentMetadata for the second method.

As a result if you use pipe-based validation with for example ValidationPipe you are in trouble. The bug is still present in 6.6.3.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings