Skip to content

Instantly share code, notes, and snippets.

@fredarend
Last active October 16, 2020 13:59
Show Gist options
  • Save fredarend/dd059f6cf309a1dc9eefca09eda123de to your computer and use it in GitHub Desktop.
Save fredarend/dd059f6cf309a1dc9eefca09eda123de to your computer and use it in GitHub Desktop.
errorBulkCreate
{
"error": {
"message": "null value in column \"course_id\" violates not-null constraint",
"name": "SequelizeDatabaseError",
"frames": [
{
"file": "node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"method": "Query.formatError",
"line": 366,
"column": 16,
"context": {
"start": 361,
"pre": " parent: err\n });\n }\n // falls through\n default:",
"line": " return new sequelizeErrors.DatabaseError(err);",
"post": " }\n }\n\n isForeignKeysQuery() {\n return /SELECT conname as constraint_name, pg_catalog\\.pg_get_constraintdef\\(r\\.oid, true\\) as condef FROM pg_catalog\\.pg_constraint r WHERE r\\.conrelid = \\(SELECT oid FROM pg_class WHERE relname = '.*' LIMIT 1\\) AND r\\.contype = 'f' ORDER BY 1;/.test(this.sql);"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"method": null,
"line": 72,
"column": 18,
"context": {
"start": 67,
"pre": " connection._invalid = true;\n }\n\n err.sql = sql;\n err.parameters = parameters;",
"line": " throw this.formatError(err);",
"post": " })\n .then(queryResult => {\n complete();\n\n let rows = Array.isArray(queryResult)"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\dialects\\postgres\\query.js",
"method": "Query.run",
"line": 64,
"column": 23,
"context": {
"start": 59,
"pre": " ? new Promise((resolve, reject) => connection.query(sql, parameters, (error, result) => error ? reject(error) : resolve(result)))\n : new Promise((resolve, reject) => connection.query(sql, (error, result) => error ? reject(error) : resolve(result)));\n\n const complete = this._logQuery(sql, debug, parameters);\n",
"line": " return query.catch(err => {",
"post": " // set the client so that it will be reaped if the connection resets while executing\n if (err.code === 'ECONNRESET') {\n connection._invalid = true;\n }\n"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\sequelize.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\sequelize.js",
"method": null,
"line": 645,
"column": 29,
"context": {
"start": 640,
"pre": " : this.connectionManager.getConnection(options);\n }).then(connection => {\n const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())",
"line": " .then(() => query.run(sql, bindParameters))",
"post": " .finally(() => this.runHooks('afterQuery', options, query))\n .finally(() => {\n if (!options.transaction) {\n return this.connectionManager.releaseConnection(connection);\n }"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\sequelize.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\sequelize.js",
"method": null,
"line": 645,
"column": 12,
"context": {
"start": 640,
"pre": " : this.connectionManager.getConnection(options);\n }).then(connection => {\n const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())",
"line": " .then(() => query.run(sql, bindParameters))",
"post": " .finally(() => this.runHooks('afterQuery', options, query))\n .finally(() => {\n if (!options.transaction) {\n return this.connectionManager.releaseConnection(connection);\n }"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\sequelize.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\sequelize.js",
"method": null,
"line": 641,
"column": 10,
"context": {
"start": 636,
"pre": " checkTransaction();\n\n return options.transaction\n ? options.transaction.connection\n : this.connectionManager.getConnection(options);",
"line": " }).then(connection => {",
"post": " const query = new this.dialect.Query(connection, this, options);\n return this.runHooks('beforeQuery', options, query)\n .then(() => checkTransaction())\n .then(() => query.run(sql, bindParameters))\n .finally(() => this.runHooks('afterQuery', options, query))"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\retry-as-promised\\index.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\retry-as-promised\\index.js",
"method": null,
"line": 70,
"column": 21,
"context": {
"start": 65,
"pre": " if (backoffTimeout) clearTimeout(backoffTimeout);\n reject(new TimeoutError(options.name + ' timed out', lastError));\n }, options.timeout);\n }\n",
"line": " Promise.resolve(callback({ current: options.$current }))",
"post": " .then(resolve)\n .then(function() {\n if (timeout) clearTimeout(timeout);\n if (backoffTimeout) clearTimeout(backoffTimeout);\n })"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\retry-as-promised\\index.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\retry-as-promised\\index.js",
"method": "retryAsPromised",
"line": 60,
"column": 10,
"context": {
"start": 55,
"pre": " };\n\n if (!Array.isArray(options.match)) options.match = [options.match];\n options.report('Trying ' + options.name + ' #' + options.$current + ' at ' + new Date().toLocaleTimeString(), options);\n",
"line": " return new Promise(function(resolve, reject) {",
"post": " var timeout, backoffTimeout, lastError;\n\n if (options.timeout) {\n timeout = setTimeout(function() {\n if (backoffTimeout) clearTimeout(backoffTimeout);"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\sequelize.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\sequelize.js",
"method": null,
"line": 631,
"column": 30,
"context": {
"start": 626,
"pre": " }\n };\n\n const retryOptions = Object.assign({}, this.options.retry, options.retry || {});\n",
"line": " return Promise.resolve(retry(() => Promise.try(() => {",
"post": " if (options.transaction === undefined && Sequelize._cls) {\n options.transaction = Sequelize._cls.get('transaction');\n }\n\n checkTransaction();"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\sequelize.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\sequelize.js",
"method": "Sequelize.query",
"line": 580,
"column": 23,
"context": {
"start": 575,
"pre": " //if user wants to always prepend searchPath (dialectOptions.preprendSearchPath = true)\n //then set to DEFAULT if none is provided\n options.searchPath = 'DEFAULT';\n }\n",
"line": " return Promise.try(() => {",
"post": " if (typeof sql === 'object') {\n if (sql.values !== undefined) {\n if (options.replacements !== undefined) {\n throw new Error('Both `sql.values` and `options.replacements` cannot be set at the same time');\n }"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\query-interface.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\query-interface.js",
"method": "QueryInterface.bulkInsert",
"line": 997,
"column": 27,
"context": {
"start": 992,
"pre": " */\n bulkInsert(tableName, records, options, attributes) {\n options = _.clone(options) || {};\n options.type = QueryTypes.INSERT;\n",
"line": " return this.sequelize.query(",
"post": " this.QueryGenerator.bulkInsertQuery(tableName, records, options, attributes),\n options\n ).then(results => results[0]);\n }\n"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\model.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\model.js",
"method": null,
"line": 2717,
"column": 39,
"context": {
"start": 2712,
"pre": " // Map returning attributes to fields\n if (options.returning && Array.isArray(options.returning)) {\n options.returning = options.returning.map(attr => model.rawAttributes[attr].field || attr);\n }\n",
"line": " return model.QueryInterface.bulkInsert(model.getTableName(options), records, options, fieldMappedAttributes).then(results => {",
"post": " if (Array.isArray(results)) {\n results.forEach((result, i) => {\n const instance = instances[i];\n\n for (const key in result) {"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\model.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\model.js",
"method": null,
"line": 2669,
"column": 12,
"context": {
"start": 2664,
"pre": "\n instance[include.association.accessors.set](associationInstance, { save: false, logging: options.logging });\n }\n });\n });",
"line": " }).then(() => {",
"post": " // Create all in one query\n // Recreate records from instances to represent any changes made in hooks or validation\n records = instances.map(instance => {\n const values = instance.dataValues;\n"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "internal/timers.js",
"filePath": "internal/timers.js",
"method": "processImmediate",
"line": 439,
"column": 21,
"context": {},
"isModule": false,
"isNative": true,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\model.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\model.js",
"method": "recursiveBulkCreate",
"line": 2618,
"column": 10,
"context": {
"start": 2613,
"pre": " if (errors.length) {\n throw errors;\n }\n });\n }",
"line": " }).then(() => {",
"post": " if (options.individualHooks) {\n // Create each instance individually\n return Promise.map(instances, instance => {\n const individualOptions = _.clone(options);\n delete individualOptions.fields;"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "node_modules\\sequelize\\lib\\model.js",
"filePath": "C:\\MyApps\\efabet-backend\\node_modules\\sequelize\\lib\\model.js",
"method": "Function.bulkCreate",
"line": 2846,
"column": 12,
"context": {
"start": 2841,
"pre": " return model.runHooks('afterBulkCreate', instances, options);\n }\n }).then(() => instances);\n };\n",
"line": " return recursiveBulkCreate(instances, options);",
"post": " }\n\n /**\n * Truncate all instances of the model. This is a convenient method for Model.destroy({ truncate: true }).\n *"
},
"isModule": true,
"isNative": false,
"isApp": false
},
{
"file": "src\\app\\controllers\\CourseController.js",
"filePath": "C:\\MyApps\\efabet-backend\\src\\app\\controllers\\CourseController.js",
"method": "store",
"line": 52,
"column": 42,
"context": {
"start": 47,
"pre": " return {\n course_id: id,\n organization_id: organization,\n };\n });",
"line": " await CoursesOrganizations.bulkCreate(organizationsArray);",
"post": "\n const { companies } = req.body;\n const companiesArray = companies.map(async (company) => {\n const companyExists = await Company.findByPk(company);\n if (!companyExists) {"
},
"isModule": false,
"isNative": false,
"isApp": true
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment