-
Error occur when in service I create an entity Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance's identity map, use |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 28 replies
-
I am having hard times understanding your english... What about using full sentences? You know, subject, verb, object :] That validation error is throw if you don't have request context set up correctly, or in general when you try to work with global entity manager, outside of request scope handler. In nest the request context is set up automatically, unless you disable it via Ideally create a reproduction project, will be happy to look into it. The realworld example project works fine in this sense, so you can try to compare what you have to that. |
Beta Was this translation helpful? Give feedback.
-
Looks like there is a bug in the nest/fastify platform or somewhere down that path, that is causing the context to be lost for requests with payload (so post/put/patch). (that issue is about different libraries, but the problem is the same, they also use I was able to make it work with fastify by using nestjs request scopes instead: import { MikroOrmModule } from '@mikro-orm/nestjs'
import { Module, Scope } from '@nestjs/common';
@Module({
imports: [
MikroOrmModule.forRoot({
registerRequestContext: false, // disable the automatic context
scope: Scope.REQUEST, // use nestjs request scopes instead
dbName: 'test.db',
debug: true,
type: 'sqlite',
entities: [__dirname + '/modules/**/entities/*.entity.js'],
entitiesTs: [__dirname + '/modules/**/entities/*.entity.ts'],
}),
UsersModule
]
})
export class AppModule {
} Note that I also used edit: with @Module({
imports: [
MikroOrmModule.forRootAsync({
useFactory: () => ({
registerRequestContext: false,
dbName: 'test.db',
debug: true,
type: 'sqlite',
entities: [__dirname + '/modules/**/entities/*.entity.js'],
entitiesTs: [__dirname + '/modules/**/entities/*.entity.ts'],
}),
scope: Scope.REQUEST,
}),
UsersModule
]
})
export class AppModule {
} |
Beta Was this translation helpful? Give feedback.
-
Fixt https://github.com/fastify/fastify/blob/e9e889a21cac35e799603a006ccfed65636b390f/lib/contentTypeParser.js (edited) |
Beta Was this translation helpful? Give feedback.
-
I found the same issue today with the update to version 5.0.0-rc.2 init options : |
Beta Was this translation helpful? Give feedback.
-
I read the stackoverflow and came here, thanks for putting the correct answer up. I just want to point out that the design on It's too easy to just use global and solve any immediate development issues. Sometimes the issues you get from this can only be noticed in production which makes the issue rather nasty and perhaps hard to even debug. I would suggest totally removing this config so that people don't use it by accident and instead perhaps add an API with a warning in the name for anyone that would need it - something along the lines of |
Beta Was this translation helpful? Give feedback.
Fixt https://github.com/fastify/fastify/blob/e9e889a21cac35e799603a006ccfed65636b390f/lib/contentTypeParser.js (edited)