question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Transactions not working as expected

See original GitHub issue

Hi - great work on Knex first of all! however having some trouble with transactions. I followed the example from the docs but it didn’t work so tried to simplify it more and can’t even get the following to work:

var Promise = require('bluebird');

knex.transaction(function(trx) {
    return trx
        .insert({
            name: 'category1'
        }, 'id')
        .into('category')
        .then(function(ids) {
            return trx
                  .insert({item2: 'second' + ids[0] }) //used 'item2' to force mysql error
                  .into('books');
        });
    })
    .then(function(inserts) {
        console.log(inserts.length + ' new books saved.'); // when it gets to here, both are inserted
    })
    .catch(function(error) {
        console.error('Error', error); // When it gets to here, only category is inserted
    });
})

I would have thought since the second insert is failing, it would rollback the first insert of ‘category1’ or am I misunderstanding how transactions work? Could there MySQL settings I’m missing or any advice on how to debug this?

MySQL version 5.5.33 if it makes any difference. Thanks in advance!

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
johnbrettcommented, Oct 25, 2014

OK guys think I figured it out! It seems transactions only work with innoDB, where the existing tables I had are MyISAM, apologies if you had that documented already! was it something you were aware of? I very much appreciate you looking into it in such detail on the weekend!! First time I’ve ever been hit by a difference in the two storage engines!

https://gist.github.com/c63ebaff3c9ed5c8f56c

Failed to reproduce this in SQLite and MySQL.

[image: Terminal output] https://camo.githubusercontent.com/b79756f0d32957f5a0c556b42133be743866d20a/687474703a2f2f662e636c2e6c792f6974656d732f31343063326b33383159304c306a316d3036306c2f53637265656e25323053686f74253230323031342d31302d32352532306174253230392e31312e3231253230414d2e706e67

— Reply to this email directly or view it on GitHub https://github.com/tgriesser/knex/issues/541#issuecomment-60482325.

0reactions
johnbrettcommented, Oct 25, 2014

OK fair enough! Cheers for the help on this guys! On 25 Oct 2014 19:59, “Ben Drucker” notifications@github.com wrote:

Did a little poking around and it does look like that’s the case. I don’t see a need to document it since I doubt many people are on MyISAM and since it’s a nonstandard choice I think it’s reasonable to assume that most people are aware of its missing features. If not they’ll be able to find this issue.

— Reply to this email directly or view it on GitHub https://github.com/tgriesser/knex/issues/541#issuecomment-60493690.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transactions not working as expected - Snowflake Community
I use transactions. When I execute both queries in parallel I expect: First query would lock the table and insert the rows ...
Read more >
Laravel Transaction Not Working as Expected - Stack Overflow
To stop even attempting the application, added the Transaction Code. DB::beginTransaction() Steps 1-4 DB::commit(). I thought this would solve ...
Read more >
Transactions not working as expected · Issue #541 · knex/knex
Hi - great work on Knex first of all! however having some trouble with transactions. I followed the example from the docs but...
Read more >
Transaction Console Is Not Working As Expected For Custom ...
Symptoms. A custom role was created to allow users access to Transaction console. The following roles were assigned to the customer role:.
Read more >
Couchbase attempt context transaction not working as expected
When there are multiple requests for updating the same document in a AttemptContext transaction block, data becomes inconsistent because of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found