{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/8279","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/8279/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/8279/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/8279/events","html_url":"https://github.com/sequelize/sequelize/issues/8279","id":256454893,"number":8279,"title":"Automatically pass transactions to all queries in automanaged transaction not works","user":{"login":"alexey2baranov","id":19248996,"avatar_url":"https://avatars1.githubusercontent.com/u/19248996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexey2baranov","html_url":"https://github.com/alexey2baranov","followers_url":"https://api.github.com/users/alexey2baranov/followers","following_url":"https://api.github.com/users/alexey2baranov/following{/other_user}","gists_url":"https://api.github.com/users/alexey2baranov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexey2baranov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexey2baranov/subscriptions","organizations_url":"https://api.github.com/users/alexey2baranov/orgs","repos_url":"https://api.github.com/users/alexey2baranov/repos","events_url":"https://api.github.com/users/alexey2baranov/events{/privacy}","received_events_url":"https://api.github.com/users/alexey2baranov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-09-09T17:52:59Z","updated_at":"2017-09-13T04:40:00Z","closed_at":null,"author_association":"NONE","body":"## What you are doing?\r\ntwo operations inside automatic transaction\r\n\r\n<!-- Post a minimal, self-contained code sample that reproduces the issue, including models and associations -->\r\n\r\n```js\r\n    result = await models.sequelize.transaction(async() => {\r\n      model = await models[type].create(plain)\r\n      attachment = await models.File.findById(EACH_ATTACHMENT)\r\n    })\r\n```\r\n\r\n## What do you expect to happen?\r\ni wana see transaction and two operations (create and select) inside it \r\n\r\n## What is actually happening?\r\ntransaction opened, then create operation inside it, then select operation outside it (see logs)\r\n\r\n_Output, either JSON or SQL_\r\n\r\n> [2017-09-09 22:44:40.329] [INFO] console - Executing (6d360132-f594-46c3-8355-74ad34aa759e): START TRANSACTION;\r\n> [2017-09-09 22:44:40.330] [INFO] console - Executing (6d360132-f594-46c3-8355-74ad34aa759e): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\r\n> [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 *;\r\n> [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);\r\n> [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'\r\n\r\n__Dialect:__postgres\r\n__Database version:9.5\r\n__Sequelize version:3.30.4\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/329056836","html_url":"https://github.com/sequelize/sequelize/issues/8279#issuecomment-329056836","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/8279","id":329056836,"user":{"login":"alexey2baranov","id":19248996,"avatar_url":"https://avatars1.githubusercontent.com/u/19248996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexey2baranov","html_url":"https://github.com/alexey2baranov","followers_url":"https://api.github.com/users/alexey2baranov/followers","following_url":"https://api.github.com/users/alexey2baranov/following{/other_user}","gists_url":"https://api.github.com/users/alexey2baranov/gists{/gist_id}","starred_url":"https://api.github.com/users/alexey2baranov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexey2baranov/subscriptions","organizations_url":"https://api.github.com/users/alexey2baranov/orgs","repos_url":"https://api.github.com/users/alexey2baranov/repos","events_url":"https://api.github.com/users/alexey2baranov/events{/privacy}","received_events_url":"https://api.github.com/users/alexey2baranov/received_events","type":"User","site_admin":false},"created_at":"2017-09-13T04:40:00Z","updated_at":"2017-09-13T04:40:00Z","author_association":"NONE","body":"this short test illustrates issue. as you can see there are two equal tests. first one is in new async/await syntax, second one is old-school promise then.then.then syntax. Old-school works perfect. But new async/await syntax execute first query in tran only. \r\n```js\r\n    describe.only('cls transaction github issue', () => {\r\n      it('async/await syntax', (done) => {\r\n        models.sequelize.transaction(async (t1) => {\r\n          await model.sequelize.query(\"select 1\", {type: model.Sequelize.QueryTypes.SELECT})\r\n          await model.sequelize.query(\"select 2\", {type: model.Sequelize.QueryTypes.SELECT})\r\n          await model.sequelize.query(\"select 3\", {type: model.Sequelize.QueryTypes.SELECT})\r\n          if (models.sequelize.Sequelize.cls.get('transaction') !== t1) {\r\n            done(\"transaction !== t1\")\r\n          }\r\n        })\r\n      })\r\n\r\n      it('then.then.then syntax', (done) => {\r\n        models.sequelize.transaction((t1) => {\r\n          return model.sequelize.query(\"select 1\", {type: model.Sequelize.QueryTypes.SELECT})\r\n            .then(() => {\r\n              return model.sequelize.query(\"select 2\", {type: model.Sequelize.QueryTypes.SELECT})\r\n            })\r\n            .then(() => {\r\n              return model.sequelize.query(\"select 3\", {type: model.Sequelize.QueryTypes.SELECT})\r\n            })\r\n            .then(() => {\r\n              if (models.sequelize.Sequelize.cls.get('transaction') !== t1) {\r\n                done(\"transaction !== t1\")\r\n              }\r\n              else {\r\n                done()\r\n              }\r\n            })\r\n        })\r\n      })\r\n    })\r\n```\r\n\r\n> Executing (be60f2c1-ec61-49b3-b728-a5f1b9ca97af): START TRANSACTION;\r\n> Executing (be60f2c1-ec61-49b3-b728-a5f1b9ca97af): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\r\n> Executing (be60f2c1-ec61-49b3-b728-a5f1b9ca97af): select 1\r\n> Executing (default): select 2\r\n> Executing (default): select 3\r\n> Executing (be60f2c1-ec61-49b3-b728-a5f1b9ca97af): COMMIT;\r\n> \r\n> Error: done() invoked with non-Error: transaction !== t1\r\n>     at models.sequelize.transaction (test/Infrastructure.Test.js:50:13)\r\n>     at <anonymous>\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): START TRANSACTION;\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): select 1\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): select 2\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): select 3\r\n> Executing (a2652943-2001-4a56-a389-33083d3325b6): COMMIT;\r\n"}}
{"actor":{"display_login":"alexey2baranov"}}