javascript - Sequelize transaction error -


trying implement oauth2. stuck sequelize transactions.

getting error:

executing (9edf48f7-5823-4b4f-b444-faa4c1896831): start transaction;

executing (9edf48f7-5823-4b4f-b444-faa4c1896831): commit;

unhandled rejection error: commit has been called on transaction(9edf48f7-5823-4b4f-b444-faa4c1896831), can no longer use it. (the rejected query attached 'sql' property of error)

`

at.save({transaction: t}).then(() => {                 rt.save({transaction: t}).then(() => {                     t.commit();                     return done(false, accesstoken, refreshtoken, {                         expires_at: expires,                         scope: scope});                 }).error(function(                     err) {                     t.rollback();                     return done(err);                 });             }).error(function(err) {                 t.rollback();                 return done(err);             }); 

sequelize 4.x.x postgres

when working sequelize transactions using auto-commit feature, need make sure return promises each of queries. looks didn't return promise nested queries, means original promise resolves after first query, commits transaction. in order wait entire chain of commits finish, must return nested promises.

return sequelize.transaction(t => {   return at.save({ transaction: t })     .then(() => {       return rt.save({ transaction: t })         .then(() => {           return t.commit() // commit returns promise, want finish             .then(() => {               return done();             });         });     }); }); 

in example above can omit t.commit() call because sequelize automatically commits transaction if promise chain resolves. if not using callback style transaction should keep there. in example used callback style.

good luck! :)


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -