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

disableIdentityMap fails with global context #2778

Closed
kristijanhusak opened this issue Feb 17, 2022 · 1 comment
Closed

disableIdentityMap fails with global context #2778

kristijanhusak opened this issue Feb 17, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@kristijanhusak
Copy link

Describe the bug
When using disableIdentityMap on the queries, I would expect that check for the Request context wouldn't trigger, because this flag will fork the entity manager every time

Stack trace

Error: ValidationError: Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead.
    at Function.cannotUseGlobalContext (/src/node_modules/@mikro-orm/core/errors.js:83:16)
    at SqlEntityManager.getContext (/src/node_modules/@mikro-orm/core/EntityManager.js:665:44)
    at CustomerRepository.get em [as em] (/src/node_modules/@mikro-orm/knex/SqlEntityRepository.js:30:25)
    at CustomerRepository.findAll (/src/node_modules/@mikro-orm/core/entity/EntityRepository.js:63:21)
    at AppService.getCustomersFromScript (/src/src/app.service.ts:17:22)
    at execute (/src/scripts/test.ts:10:32)

To Reproduce
Steps to reproduce the behavior:

  1. clone https://github.com/kristijanhusak/mikroorm-migration-issue
  2. start with docker-compose up
  3. Run the script with docker-compose exec api node_modules/.bin/ts-node scripts/test.ts

Expected behavior
Expected to be able to run the query because I passed disableIdentityMap: true to it. Code here.

Versions

Dependency Version
node 16.13.0
typescript 4.55
mikro-orm 5.0.1
your-driver postgres
@B4nan B4nan added the bug Something isn't working label Feb 17, 2022
@B4nan
Copy link
Member

B4nan commented Feb 17, 2022

The problem is actually only if you use repository, as the validation is triggered by accessing the EM from a repository (which takes the one from context automatically), not by using the EM API directly.

@B4nan B4nan closed this as completed in f651865 Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants