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

Transaction rollback does not work #23

Closed
luaneyed opened this issue Mar 13, 2019 · 2 comments
Closed

Transaction rollback does not work #23

luaneyed opened this issue Mar 13, 2019 · 2 comments
Labels

Comments

@luaneyed
Copy link
Contributor

try {
    await Connection.transaction({ models: [ModelClass] }, (ModelClassTx) => {
      // [Job 1] do something using ModelClassTx
      throw new Error('An intentional error');
      // [Job 2] do something using ModelClassTx

      return Promise.resolve();
    });
  } catch (error) {
    return { error };
  }

I expect the above code affect nothing to db, but Job 1 is committed!
Exactly, the job is committed when MySQLAdapter::rollbackTransaction is executed.

@luaneyed luaneyed added the bug label Mar 13, 2019
@sixmen
Copy link
Member

sixmen commented Mar 13, 2019

I already have a test case for that.

it('transaction fail', async () => {

Please give a more detail for the problem.

@luaneyed
Copy link
Contributor Author

I solved it.
All queries should be executed before returning the transaction block.

I think it's just a matter of order.

[ what I wanted ]

START TRANSACTION
SQL-1
SQL-2
ROLLBACK

[ what happened with my asynchronous code ]

START TRANSACTION
ROLLBACK
SQL-1
SQL-2

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

No branches or pull requests

2 participants