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

A method handler is interfering into another handler with same name in another controller. #2663

Closed
daniel-dia opened this issue Jul 28, 2019 · 6 comments

Comments

@daniel-dia
Copy link

daniel-dia commented Jul 28, 2019

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
@daniel-dia daniel-dia added the needs triage This issue has not been looked into label Jul 28, 2019
@kamilmysliwiec
Copy link
Member

Please, provide a minimal repository which reproduces your issue.

@kamilmysliwiec kamilmysliwiec added needs clarification and removed needs triage This issue has not been looked into labels Jul 29, 2019
@xyunsh
Copy link

xyunsh commented Jul 30, 2019

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.

@kamilmysliwiec
Copy link
Member

Thanks! I'll push fix asap

@kamilmysliwiec
Copy link
Member

Fixed in 6.6.0 :)

@vimmerru
Copy link

@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.

@lock
Copy link

lock bot commented Nov 28, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants