{"action":"reopened","issue":{"url":"https://api.github.com/repos/sequelize/sequelize/issues/3781","repository_url":"https://api.github.com/repos/sequelize/sequelize","labels_url":"https://api.github.com/repos/sequelize/sequelize/issues/3781/labels{/name}","comments_url":"https://api.github.com/repos/sequelize/sequelize/issues/3781/comments","events_url":"https://api.github.com/repos/sequelize/sequelize/issues/3781/events","html_url":"https://github.com/sequelize/sequelize/issues/3781","id":78942225,"number":3781,"title":"Error: Cannot find module 'pg-native'","user":{"login":"tornillo","id":2512027,"avatar_url":"https://avatars3.githubusercontent.com/u/2512027?v=4","gravatar_id":"","url":"https://api.github.com/users/tornillo","html_url":"https://github.com/tornillo","followers_url":"https://api.github.com/users/tornillo/followers","following_url":"https://api.github.com/users/tornillo/following{/other_user}","gists_url":"https://api.github.com/users/tornillo/gists{/gist_id}","starred_url":"https://api.github.com/users/tornillo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tornillo/subscriptions","organizations_url":"https://api.github.com/users/tornillo/orgs","repos_url":"https://api.github.com/users/tornillo/repos","events_url":"https://api.github.com/users/tornillo/events{/privacy}","received_events_url":"https://api.github.com/users/tornillo/received_events","type":"User","site_admin":false},"labels":[{"id":28979678,"url":"https://api.github.com/repos/sequelize/sequelize/labels/bug","name":"bug","color":"d7e102","default":true}],"state":"open","locked":false,"assignee":{"login":"janmeier","id":1210224,"avatar_url":"https://avatars3.githubusercontent.com/u/1210224?v=4","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},"assignees":[{"login":"janmeier","id":1210224,"avatar_url":"https://avatars3.githubusercontent.com/u/1210224?v=4","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":19,"created_at":"2015-05-21T10:55:32Z","updated_at":"2018-04-29T07:07:05Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Exception occurs when trying to add two (or more) equal values in a unique field using findOrCreate.\n\nTest code:\n\n``` javascript\nvar arr = [0, 1];\n\nvar User = sequelize.define('User', {\n    login: {\n        type: Sequelize.STRING,\n        unique: true\n    }\n});\n\nUser.sync({ force: true })\n.then(function () {\n    sequelize.transaction()\n    .then(function (tx) {\n        return Promise.map(arr, function () {\n            return User.findOrCreate({\n                where: {\n                    login: 'test'\n                },\n                transaction: tx\n            });\n        })\n        .then(function () {\n            tx.commit();\n        });\n    });\n});\n```\n\nSQL log:\n\n``` SQL\nExecuting (default): DROP TABLE IF EXISTS \"Users\" CASCADE;\nExecuting (default): CREATE TABLE IF NOT EXISTS \"Users\" (\"id\"   SERIAL , \"login\" VARCHAR(255) UNIQUE, PRIMARY KEY (\"id\"));\nExecuting (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' and t.relname = 'Users' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): START TRANSACTION;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SET autocommit = 1;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SAVEPOINT \"6a28eaa0-9716-4db0-be66-967f8ec12058-savepoint-1\";\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SAVEPOINT \"6a28eaa0-9716-4db0-be66-967f8ec12058-savepoint-2\";\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SELECT \"id\", \"login\" FROM \"Users\" AS \"User\" WHERE \"User\".\"login\" = 'test' LIMIT 1;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): SELECT \"id\", \"login\" FROM \"Users\" AS \"User\" WHERE \"User\".\"login\" = 'test' LIMIT 1;\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): CREATE OR REPLACE FUNCTION pg_temp.testfunc(OUT response \"Users\", OUT sequelize_caught_exception text) RETURNS RECORD AS $func_66f952b0ec354cdbb8923433f3248e4a$ BEGIN INSERT INTO \"Users\" (\"id\",\"login\") VALUES (DEFAULT,'test') RETURNING * INTO response; EXCEPTION WHEN unique_violation THEN GET STACKED DIAGNOSTICS sequelize_caught_exception = PG_EXCEPTION_DETAIL; END $func_66f952b0ec354cdbb8923433f3248e4a$ LANGUAGE plpgsql; SELECT (testfunc.response).*, testfunc.sequelize_caught_exception FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc();\nExecuting (6a28eaa0-9716-4db0-be66-967f8ec12058): CREATE OR REPLACE FUNCTION pg_temp.testfunc(OUT response \"Users\", OUT sequelize_caught_exception text) RETURNS RECORD AS $func_2abdfe30c027469dac0b5fe594fb4dda$ BEGIN INSERT INTO \"Users\" (\"id\",\"login\") VALUES (DEFAULT,'test') RETURNING * INTO response; EXCEPTION WHEN unique_violation THEN GET STACKED DIAGNOSTICS sequelize_caught_exception = PG_EXCEPTION_DETAIL; END $func_2abdfe30c027469dac0b5fe594fb4dda$ LANGUAGE plpgsql; SELECT (testfunc.response).*, testfunc.sequelize_caught_exception FROM pg_temp.testfunc(); DROP FUNCTION IF EXISTS pg_temp.testfunc();\n```\n\nError stack:\n\n``` javascript\nUnhandled rejection Error: Cannot find module 'pg-native'\n    at Function.Module._resolveFilename (module.js:336:15)\n    at Function.Module._load (module.js:278:25)\n    at Module.require (module.js:365:17)\n    at require (module.js:384:17)\n    at Object.<anonymous> (/home/user/test/node_modules/pg/lib/native/index.js:1:76)\n    at Module._compile (module.js:460:26)\n    at Object.Module._extensions..js (module.js:478:10)\n    at Module.load (module.js:355:32)\n    at Function.Module._load (module.js:310:12)\n    at Module.require (module.js:365:17)\n    at require (module.js:384:17)\n    at null.<anonymous> (/home/user/test/node_modules/pg/lib/index.js:78:36)\n    at /home/user/test/node_modules/lodash/index.js:3159:32\n    at baseForOwn (/home/user/test/node_modules/lodash/index.js:2089:14)\n    at baseClone (/home/user/test/node_modules/lodash/index.js:1799:39)\n    at /home/user/test/node_modules/lodash/index.js:1800:23\nFrom previous event:\n    at Promise.catch (/home/user/test/node_modules/sequelize/lib/promise.js:21:17)\n    at Object.<anonymous> (/home/user/test/node_modules/sequelize/lib/model.js:1199:15)\nFrom previous event:\n    at Promise.then (/home/user/test/node_modules/sequelize/lib/promise.js:21:17)\n    at module.exports.Model.findOrCreate (/home/user/test/node_modules/sequelize/lib/model.js:1180:8)\n    at /home/user/test/tests.js:30:16\nFrom previous event:\n    at /home/user/test/tests.js:29:18\n    at processImmediate [as _immediateCallback] (timers.js:358:17)\nFrom previous event:\n    at Promise.then (/home/user/test/node_modules/sequelize/lib/promise.js:21:17)\n    at Object.<anonymous> (/home/user/test/tests.js:26:2)\n    at Module._compile (module.js:460:26)\n    at Object.Module._extensions..js (module.js:478:10)\n    at Module.load (module.js:355:32)\n    at Function.Module._load (module.js:310:12)\n    at Function.Module.runMain (module.js:501:10)\n    at startup (node.js:129:16)\n    at node.js:814:3\n```\n\nNote: without the transaction is the same error\n"}}
{"actor":{"display_login":"sushantdhiman"}}