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

queryRunner.data when provided by ormOptions is not provided to *TransactionCommit subscribers #10150

Closed
1 of 18 tasks
nicolasroger17 opened this issue Jun 23, 2023 · 0 comments · Fixed by #10151
Closed
1 of 18 tasks

Comments

@nicolasroger17
Copy link
Contributor

nicolasroger17 commented Jun 23, 2023

Issue description

Within a transaction, the { data } object provided should also be provided to the beforeTransactionCommit, afterTransactionCommit, etc subscribers

When calling method like insert, update, save and providing OrmOptions, for example:

const myEntity = new MyEntity({ id: 1, status 1 });

await manager.transaction(async (manager) => { 
  await queryRunner.insert(myEntity, { someData: true });
  await queryRunner.update({ ...myEntity, status: 2 });
}); 

Expected Behaviour

This is what should be happening

    /**
     * Called after entity insert.
     */
    afterInsert(event: InsertEvent<any>) {
        console.log(`AFTER ENTITY INSERTED: `, event.queryRunner.data) // ✅ 
    }

    /**
     * Called after entity update.
     */
    afterUpdate(event: UpdateEvent<any>) {
        console.log(`AFTER ENTITY UPDATED: `, event.queryRunner.data) // ✅ 
    }

    /**
     * Called after transaction commit.
     */
    afterTransactionCommit(event: TransactionCommitEvent) {
        console.log(`AFTER TRANSACTION COMMITTED: `, event.queryRunner.data) // ✅  
    }

Actual Behavior

This is what is happening

    /**
     * Called after entity insert.
     */
    afterInsert(event: InsertEvent<any>) {
        console.log(`AFTER ENTITY INSERTED: `, event.queryRunner.data) // ✅ 
    }

    /**
     * Called after entity update.
     */
    afterUpdate(event: UpdateEvent<any>) {
        console.log(`AFTER ENTITY UPDATED: `, event.queryRunner.data) // ✅ 
    }

    /**
     * Called after transaction commit.
     */
    afterTransactionCommit(event: TransactionCommitEvent) {
        console.log(`AFTER TRANSACTION COMMITTED: `, event.queryRunner.data) // ❌ 
    }

Steps to reproduce

Here's a PR with the test that shows the issue (if you remove the fix it'll fail)
https://github.com/typeorm/typeorm/pull/10151/files

My Environment

Dependency Version
Operating System Mac/Linux
Node.js version 18.15.0
Typescript version 5.0.4
TypeORM version 0.3.1.0

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant