Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transaction query already complete, run with DEBUG=knex:tx

when I work with japa test runner adonisJs 5 my test failed and got this error:

× Uncaught exception

   Transaction query already complete, run with DEBUG=knex:tx for more info


     1  completedError
       node_modules/knex/lib/execution/transaction.js:396

     2  anonymous
       node_modules/knex/lib/execution/transaction.js:362

     3  Client_MySQL2.trxClient.query
       node_modules/knex/lib/execution/transaction.js:358

     4  Runner.query
       node_modules/knex/lib/execution/runner.js:123

     5  ensureConnectionCallback
       node_modules/knex/lib/execution/internal/ensure-connection-callback.js:13

     6  Runner.ensureConnection
       node_modules/knex/lib/execution/runner.js:300

     7  Runner.run
       node_modules/knex/lib/execution/runner.js:30

     8  QueryRunner.executeQuery
       node_modules/@adonisjs/lucid/build/src/QueryRunner/index.js:78

I don't know why I get this error in some of my tests in some of i don't

japa test runner adonisJs 5

like image 865
M.Edriss Aria Avatar asked Dec 19 '25 18:12

M.Edriss Aria


1 Answers

I encountered the same issue and the issue for me was a missing await on a database call that returned a promise in one of my assertions,

so by the time the response was returned the global transaction in the test suite had already been rolled back

Once I added the await, the error was resolved, so I suggest you double check any async calls in your tests which you may not be awaiting a response for.

like image 179
Tsatsu Avatar answered Dec 21 '25 08:12

Tsatsu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!