sequelize: Automatically pass transactions to all queries in automanaged transaction not works

What you are doing?

two operations inside automatic transaction

    result = await models.sequelize.transaction(async() => {
      model = await models[type].create(plain)
      attachment = await models.File.findById(EACH_ATTACHMENT)
    })

What do you expect to happen?

i wana see transaction and two operations (create and select) inside it

What is actually happening?

transaction opened, then create operation inside it, then select operation outside it (see logs)

Output, either JSON or SQL

[2017-09-09 22:44:40.329] [INFO] console - Executing (6d360132-f594-46c3-8355-74ad34aa759e): START TRANSACTION; [2017-09-09 22:44:40.330] [INFO] console - Executing (6d360132-f594-46c3-8355-74ad34aa759e): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ; [2017-09-09 22:44:40.338] [INFO] console - Executing (6d360132-f594-46c3-8355-74ad34aa759e): INSERT INTO “Zemla” (“id”,“name”,“level”,“obshinaSize”,“path”,“created_at”,“updated_at”,“parent_id”) VALUES (DEFAULT,‘unit test’,0,0,‘/1/’,‘2017-09-09 17:44:40.331 +00:00’,‘2017-09-09 17:44:40.331 +00:00’,1) RETURNING *; [2017-09-09 22:44:40.352] [INFO] console - Executing (default): SELECT “id”, “name”, “path”, “note”, “mimeType”, “size”, “created_at”, “updated_at”, “deleted_at”, “kopa_id”, “owner_id”, “zemla_id”, “kopnik_id”, “predlozhenie_id”, “slovo_id”, “golos_id”, “registration_id” FROM “File” AS “File” WHERE (“File”.“deleted_at” IS NULL AND “File”.“id” = 1); [2017-09-09 22:44:57.603] [INFO] console - Executing (default): UPDATE “File” SET “zemla_id”=‘180’,“updated_at”=‘2017-09-09 17:44:57.590 +00:00’ WHERE “id” = ‘1’

__Dialect:__postgres __Database version:9.5 __Sequelize version:3.30.4

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Actually it looks like a bug that INSERT operation is performing in transaction