{"action":"created","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3434","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3434/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3434/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3434/events","html_url":"https://github.com/sequelize/sequelize/issues/3434","id":65393490,"number":3434,"title":"CLS transaction not used.","user":{"login":"mehmetavsar","id":4456732,"avatar_url":"https://avatars.githubusercontent.com/u/4456732?v=3","gravatar_id":"","url":"https://api.github.com/users/mehmetavsar","html_url":"https://github.com/mehmetavsar","followers_url":"https://api.github.com/users/mehmetavsar/followers","following_url":"https://api.github.com/users/mehmetavsar/following{/other_user}","gists_url":"https://api.github.com/users/mehmetavsar/gists{/gist_id}","starred_url":"https://api.github.com/users/mehmetavsar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehmetavsar/subscriptions","organizations_url":"https://api.github.com/users/mehmetavsar/orgs","repos_url":"https://api.github.com/users/mehmetavsar/repos","events_url":"https://api.github.com/users/mehmetavsar/events{/privacy}","received_events_url":"https://api.github.com/users/mehmetavsar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"janmeier","id":1210224,"avatar_url":"https://avatars.githubusercontent.com/u/1210224?v=3","gravatar_id":"","url":"https://api.github.com/users/janmeier","html_url":"https://github.com/janmeier","followers_url":"https://api.github.com/users/janmeier/followers","following_url":"https://api.github.com/users/janmeier/following{/other_user}","gists_url":"https://api.github.com/users/janmeier/gists{/gist_id}","starred_url":"https://api.github.com/users/janmeier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/janmeier/subscriptions","organizations_url":"https://api.github.com/users/janmeier/orgs","repos_url":"https://api.github.com/users/janmeier/repos","events_url":"https://api.github.com/users/janmeier/events{/privacy}","received_events_url":"https://api.github.com/users/janmeier/received_events","type":"User","site_admin":false},"milestone":null,"comments":4,"created_at":"2015-03-31T08:05:22Z","updated_at":"2015-04-03T11:02:54Z","closed_at":"2015-04-01T09:12:01Z","body":"Hi,\r\n\r\n> I've asked [this question](http://stackoverflow.com/questions/29351728/sequelize-cls-transaction-not-used) on SO, but not likely to get an answer. \r\n\r\nI'm trying implement a global transaction for all nested sequelize queries, using continuation local-storage support. I believe I've set namespace to Sequelize.cls correctly, because it works in many places as expected.\r\n\r\nWhen migrating data from SQL server to Postgresql (sequelize models bonded), nested calls do not use the transaction. Code below.\r\n\r\n    var Steps = function() {\r\n    \r\n    }\r\n    \r\n    Steps.prototype = {\r\n        constructor:Steps,\r\n        IlIlce : function() {\r\n            var connection = this.dataplex;\r\n            var request = new sql.Request(connection);\r\n            return request.execute('Migrasyon_Il').then(function (recordsets) {\r\n                console.log('-=-=-=-=' + recordsets[0].length + ' İL kaydı bulundu');\r\n                return Promise.reduce(recordsets[0], function (total, row) {\r\n                    return app.Sql.models.Il.create({\r\n                        _Isim: row.AD,\r\n                        _Entegrasyon: row.IL\r\n                    });\r\n                }, 0);\r\n            }).then(function (total) {\r\n                return total;\r\n            }).catch(function (cause) {\r\n                throw cause;\r\n            });\r\n        }\r\n        Step2 : function() {},\r\n        Step3 : function() {},\r\n        Step4 : function() {},\r\n    }\r\n\r\n\r\nI've split migration steps into the the object prototype above. It is called in PostgreSQL/Sequelize transaction as below:\r\n\r\n    module.exports = {\r\n        run: function() {\r\n            var steps = new Steps();\r\n            steps.dataplex = new sql.Connection(config);\r\n            ...\r\n       \r\n            return steps.dataplex.connect().then(function() {\r\n                // app.Sql => Sequelize instance.\r\n                return app.Sql.transaction(function () { // <-- wrapper transaction\r\n                    return Promise.delay(1).then(function() {\r\n                        return steps.IlIlce();\r\n                    }).then(function () {\r\n                        return steps.Step2();\r\n                    }).then(function () {\r\n                        return steps.Step3();\r\n                    }).then(function () {\r\n                        return steps.Step4();\r\n                        return true;\r\n                    });\r\n                });\r\n            }).then(function () {\r\n                return true;\r\n            }).catch(function (cause) {\r\n                throw cause;\r\n            }).finally(function() {\r\n                steps.dataplex.close();\r\n            });\r\n\r\nNone of the Sequelize methods in Steps functions use the wrapper transaction.\r\n\r\nI've tried to debug it like:\r\n\r\n - put a console.log() line in\r\n   Transaction.prototype.prepareEnvironment() method, where it sets\r\n   transaction in namespace. it passes.\r\n   \r\n - defined a beforeCreate() hook in Il model definition, which is used\r\n   in Steps.prototype.IlIlce method. In this method context,\r\n   Sequelize.cls.get('transaction') returns undefined.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/comments/89254362","html_url":"https://github.com/sequelize/sequelize/issues/3434#issuecomment-89254362","issue_url":"https://api.github.com/repos/sequelize/sequelize/issues/3434","id":89254362,"user":{"login":"mehmetavsar","id":4456732,"avatar_url":"https://avatars.githubusercontent.com/u/4456732?v=3","gravatar_id":"","url":"https://api.github.com/users/mehmetavsar","html_url":"https://github.com/mehmetavsar","followers_url":"https://api.github.com/users/mehmetavsar/followers","following_url":"https://api.github.com/users/mehmetavsar/following{/other_user}","gists_url":"https://api.github.com/users/mehmetavsar/gists{/gist_id}","starred_url":"https://api.github.com/users/mehmetavsar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehmetavsar/subscriptions","organizations_url":"https://api.github.com/users/mehmetavsar/orgs","repos_url":"https://api.github.com/users/mehmetavsar/repos","events_url":"https://api.github.com/users/mehmetavsar/events{/privacy}","received_events_url":"https://api.github.com/users/mehmetavsar/received_events","type":"User","site_admin":false},"created_at":"2015-04-03T11:02:54Z","updated_at":"2015-04-03T11:02:54Z","body":"@janmeier What would you expect in this case, to run the `COMMIT;` statement in or out of transaction?\r\n"}}