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

RelationLoader doesn't use transaction #5338

Closed
shayded-exe opened this issue Jan 14, 2020 · 2 comments · Fixed by #7471
Closed

RelationLoader doesn't use transaction #5338

shayded-exe opened this issue Jan 14, 2020 · 2 comments · Fixed by #7471

Comments

@shayded-exe
Copy link
Contributor

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

When trying to load a relation from an entity created during a transaction, the relation loader doesn't use the transaction from the provided entity manager.

The following code will return no results if the person entity was created during the current transaction:

let results = await manager
  .createQueryBuilder(Person, 'x')
  .relation(key)
  .of(person)
  .loadMany();
@cainlevy
Copy link

This one also got me. I went back to the docs and found the behavior partially described:

You also cannot use classes which use global manager or connection to execute their queries.
https://typeorm.io/#/transactions

This is currently happening in RelationQueryBuilder as it tries to access RelationLoader:

return this.connection.relationLoader.load(this.expressionMap.relationMetadata, of);

@shayded-exe
Copy link
Contributor Author

I don't see why it couldn't be changed to use transactions. @pleerock ? I'd be willing to work on a PR.

AlexMesser pushed a commit that referenced this issue Mar 29, 2021
* fix: pass queryRunner

pass queryRunner in order to use existing transaction

Closes: #5338

* test: add basic test

add unfinished basic test with explanation to reproduce bahavior

* test: remove only flag

* test: remove only flag

* test: remove logging

remove logging when acquiring connection

* test: automate transaction-load-many

automate transaction-load-many for postgres, mysql, mariadb

Co-authored-by: Lukas Bersinger <7009574+lukinet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants