-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
EntityManager injection broken >5.1.2 with custom factory using PinoLogger and built via ncc #128
Comments
Can you please provide a complete repro as a GH repository? Have you tried it without
This is a pretty bad idea, you are just getting around the validation, but still using a single global EM fork. This will almost certainly have unwanted side effects. |
The reproduction above is complete (
version: "3.7"
services:
db-mongo:
image: "public.ecr.aws/docker/library/mongo:3"
healthcheck:
test: ["CMD-SHELL", 'mongo --eval ''db.runCommand("ping").ok'' localhost:27017/test --quiet']
interval: 10s
timeout: 2s
retries: 10
ports:
- "27017:27017" If the version 5.1.2 works fine with This reproduction merely shows the error and how to cause it. It does not show the actual business use case which is AWS EventBridgeEvent lambda that gets/resolves various services using cached and initialized application context assigned to |
I am asking because I want to spare my time, as I have a huge amount of other issues I need to review these days. I don't want to copy past things and create files. Sounds like you value your time more than mine. That's fine, but don't expect me to also put more value on yours... |
Thanks! Maybe this one is related? vercel/ncc#776 |
Doesn't seem related. I have no issues with decorators in different projects using exactly the same ncc version and other dependencies but with sequelize instead mikro-orm. And |
You keep talking about |
No, I mean exactly what I said above and I wrote the same in the issue description. |
Oh ok, so the problem is in this package. I was suspecting some changes I did in v5.7.13 released a few days ago. Will try to look into this later this week. |
It appears that the issue is that it is calling the useFactory method without actually injecting any of the injected values. I ran into this with the config service not being injected after updating. I am not sure why it broke only on 5.7.13 (for me). |
I've added an alternative reproduction to the reproduction repository - one using
Regarding this, what would be the proper way of doing things for applications using |
I am not sure if that would help, it controls the nestjs DI scopes, and since there are no requests, I'd expect there won't be any request context in the DI either, but maybe I am wrong, haven't used nest in a long time. You could create the context explicitly via https://mikro-orm.io/docs/usage-with-nestjs#request-scoped-handlers-in-queues |
The second test is missing @Module({
providers: [MongoService],
imports: [
MikroOrmModule.forFeature([MongoEntity]),
],
})
export class MongoModule {} |
Ah, you're right, silly mistake. I fiddled with
It seems to be working fine both with ts-node and with code built via ncc. Maybe usage with Now, should the initial reproduction be considered an actual bug or an incorrect usage due to the above? If it's incorrect usage, then |
The thing is I am not completely sure how it is supposed to be working in nest di, it's been years since I used it in an actual project (same for any web app, I no longer develop those). I checked how the official nest/typeorm adapter registers things, and it feels pretty much the same as we do here, especially when it comes to
That's good news, could you PR that somewhere? e.g. the readme here, I can propagate it to mikro-orm.io myself. |
There are some edge cases around this. For example, if I make the whole MongoService in my reproduction have a scope but skip it in MikroOrmModule.forRootAsync, then I still get ValidationError when using the repository. As if injection ignored the fact that the whole service is scoped. No idea if it should somehow propagate without explicit MikroOrmModule scope being defined or not. At least I found a way to make it work with InjectRepository and solve my use-case. And it doesn't require manual forking as a workaround. |
I am more than sure you need to use the |
Describe the bug
EntityManager
(MongoEntityManager
) dependency injection cannot be resolved when using@mikro-orm/nestjs
>5.1.2 with.forRootAsync
andPinoLogger
. It works fine without injecting the logger into customuseFactory
. Happens only when executing built code.Stack trace
To Reproduce
package.json
tsconfig.json
reproduction.ts
Expected behavior
I expect the
EntityManager
to get injected correctly and work as it was working before in version 5.1.2.Additional context
The error happens only when running a built .js file. It does not occur when running .ts file via ts-node. The
mongodb
dependency is locked to version 4.1.4 because of an old MongoDB v3 instance that needs to be connected to.Versions
The text was updated successfully, but these errors were encountered: