-
-
Notifications
You must be signed in to change notification settings - Fork 31
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
IdentityMap Request Context fails in NestJS app when using app.setGlobalPrefix
#130
Comments
This example app is doing that and works just fine. You will need to provide complete repro for this. https://github.com/mikro-orm/nestjs-realworld-example-app/blob/master/src/main.ts#L8 |
@B4nan I cloned the realworld example app you linked and I managed to trigger the same bug. I found something interesting. This AppController will work fine: import { EntityManager } from '@mikro-orm/mysql';
import { Controller, Get } from '@nestjs/common';
import { Article } from './article/article.entity';
@Controller('api')
export class AppController {
constructor(private em: EntityManager) {}
@Get()
async root() {
let article = await this.em.find(Article, {});
return article;
}
} Now if I change the import { EntityManager } from '@mikro-orm/mysql';
import { Controller, Get } from '@nestjs/common';
import { Article } from './article/article.entity';
@Controller()
export class AppController {
constructor(private em: EntityManager) {}
@Get()
async root() {
let article = await this.em.find(Article, {});
return article;
}
} So conclusion is, for some reason, when the Here are the exact changes that will trigger the bug when navigating to |
I faced the same problem it was a mistake this is how the problem was solved |
Probably related: nestjs/nest#11572 I can see that using |
Closing as this should be addressed in next nest version via nestjs/nest#13337 |
Unfortunately it didn't fix the issue. The error is still present when using
|
Yeah I am aware of that, still it doesnt change the fact that this is a bug in nest. |
Describe the bug
When adding
app.setGlobalPrefix('api');
to the bootstrap function in my NestJSmain.ts
file MikroORM does no longer properly handle request context for the identity map and it gives the error:Using global EntityManager instance methods for context specific actions is disallowed
. The moment I removeapp.setGlobalPrefix('api')
everything works fine again.Stack trace
To Reproduce
Steps to reproduce the behavior:
app.setGlobalPrefix('api');
to the NestJS bootstrap function inmain.ts
EntityManager
inside the AppController and callthis.em.find(...)
inside a route function of that controller.Expected behavior
I would expect MikroORM to behave the same with and without using
app.setGlobalPrefix
.Additional context
Using it within a NestJS application.
Versions
5.7.14
The text was updated successfully, but these errors were encountered: