When I try to update an existing model with upsertGraph, I get the following error (full stacktrace):
Error: undefined passed as argument #1 for 'whereComposite' operation. Call skipUndefined() method to ignore the undefined values.
at convertUndefined (/project/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:67:11)
at convertArgs (/project/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:38:14)
at WhereCompositeOperation.onAdd (/project/node_modules/objection/lib/queryBuilder/operations/ObjectionToKnexConvertingOperation.js:22:17)
at QueryBuilder.addOperation (/project/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:147:33)
at QueryBuilder.whereComposite (/project/node_modules/objection/lib/queryBuilder/QueryBuilderBase.js:485:17)
at InstanceUpdateOperation.onBuild (/project/node_modules/objection/lib/queryBuilder/operations/InstanceUpdateOperation.js:30:13)
at QueryBuilder.buildInto (/project/node_modules/objection/lib/queryBuilder/QueryBuilderOperationSupport.js:190:10)
at buildInto (/project/node_modules/objection/lib/queryBuilder/QueryBuilder.js:1129:25)
at Object.<anonymous> (/project/node_modules/objection/lib/queryBuilder/QueryBuilder.js:532:25)
at Object.tryCatcher (/project/node_modules/objection/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/project/node_modules/objection/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/project/node_modules/objection/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/project/node_modules/objection/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/project/node_modules/objection/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/project/node_modules/objection/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/project/node_modules/objection/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/project/node_modules/objection/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:785:20)
at tryOnImmediate (timers.js:747:5)
at processImmediate [as _immediateCallback] (timers.js:718:5)
When I am calling the upsertGraph operation, I am passing in the model root id. As a last-ditch effort to try and understand what is happening, I went into ObjectionToKnexConvertingOperation.js and logged args under the convertArgs function. I also turned on debug().
For the following update:
{
"title": "Mytitle",
"startDate": "2018-06-18T08:07:09.728Z",
"createdAt": "2017-11-07T00:18:56.511Z",
"id": "9"
}
I got the following log output from convertArgs:
{ '0': 'meetings.id', '1': [ '9' ] }
[ 'meetings.id' ]
[]
{ method: 'select',
options: {},
timeout: false,
cancelOnTimeout: false,
bindings: [ '9' ],
__knexQueryUid: 'e2e4b1fa-e77d-4848-a05b-838785667a3d',
sql: 'select "meetings"."id" from "meetings" where "meetings"."id" in (?)' }
[]
[]
{ '0': 'meetings.id', '1': undefined }
It seems as if at some point, the root id is undefined? I should also note that I went into the database schema and removed all the onDelete('CASCADE') parts, in case that was interfering.
Thank you!
Could you post the actual query that fails with the actual data that fails?
Hi there,
I am assuming that upsertGraph is completely broken and every query seems to be giving that error. I originally had some relations in my query but stripped them out in the debugging process.
I would be happy to post a full query. Give me a few minutes
Sigh.. I can assure you that upsertGraph is not completely broken. It has a quite comprehensive test suite. Please in the future, don't assume that and provide enough information for us to help you. 95% of the time the problem is in the users's code and not in objection.
The problem was that I had a $beforeUpdate hook that was stripping out the id. You were right!
Most helpful comment
Sigh.. I can assure you that upsertGraph is not completely broken. It has a quite comprehensive test suite. Please in the future, don't assume that and provide enough information for us to help you. 95% of the time the problem is in the users's code and not in objection.