Undefined binding(s) detected when using sendConfirmationEmail

System Information
  • Strapi Version: 4.1.12
  • Operating System: ubuntu
  • Database: mysql
  • Node Version: 16.17.0
  • NPM Version: 8.15.0
  • Yarn Version:

When trying to us await strapi.plugins["users-permissions"].services.user.sendConfirmationEmail(user); i get the below error. I do not get the error when a user registers and the system sends an email, only this database error when I call it directly from a controller I also tried from a cron.

the database debug seems like it should work. i don’t understand the error.
It dies on /node_modules/@strapi/plugin-users-permissions/server/services/user.js:51 in edit()
I am not sure what the next steps to debugging this are.

  method: 'first',
  options: {},
  timeout: false,
  cancelOnTimeout: false,
  bindings: [ 8, 1 ],
  __knexQueryUid: 'SJpSDtbL4CNxqVZBaLunQ',
  sql: 'select `t0`.* from `up_users` as `t0` where (`t0`.`id` = ?) limit ?'
}
[2022-09-03 05:06:00.056] error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`id` = ?
Error: Undefined binding(s) detected when compiling WHERE. Undefined column(s): [t0.id] query: where `t0`.`id` = ?
    at QueryCompiler_MySQL.toSQL (/app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:110:13)
    at compileCallback (/app/artefy-shared/node_modules/knex/lib/formatter/formatterUtils.js:13:19)
    at rawOrFn (/app/artefy-shared/node_modules/knex/lib/formatter/wrappingFormatter.js:225:7)
    at QueryCompiler_MySQL.whereWrapped (/app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:1066:17)
    at QueryCompiler_MySQL.where (/app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:555:34)
    at /app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:130:40
    at Array.map (<anonymous>)
    at QueryCompiler_MySQL.select (/app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:129:35)
    at QueryCompiler_MySQL.toSQL (/app/artefy-shared/node_modules/knex/lib/query/querycompiler.js:73:29)
    at Builder.toSQL (/app/artefy-shared/node_modules/knex/lib/query/querybuilder.js:83:44)
    at ensureConnectionCallback (/app/artefy-shared/node_modules/knex/lib/execution/internal/ensure-connection-callback.js:4:30)
    at Runner.ensureConnection (/app/artefy-shared/node_modules/knex/lib/execution/runner.js:307:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Runner.run (/app/artefy-shared/node_modules/knex/lib/execution/runner.js:30:19)
    at async Object.execute (/app/artefy-shared/node_modules/@strapi/database/lib/query/query-builder.js:354:22)
    at async Object.findOne (/app/artefy-shared/node_modules/@strapi/database/lib/entity-manager.js:118:22)```

I couldn’t edit any more but I have narrowed down where the error happens.
/node_modules/@strapi/strapi/lib/services/entity-service/index.js line 220 let entity = await db.query(uid).update({

I don’t believe there is a lifestyle hook doing anything (since I think that happens before now)

i hard coded the where: { id: entityId } to where: { id: 8 } and still get the error.

the up_users table has an id column.

I found the solution, there was a beforeUpdate hook that I did not know about or could not find, the hook was performing a findOne with an unidentified id field.

I found this by adding a log.trace('findOne') into node_modules/knex/lib/query/querycompiler.js line 109 after if (this._undefinedInWhereClause) { this gave me enough trace info to see exactly where the error was happening.

1 Like

With Strapi 4.4.5,

I have the same problem with lifecycles, when I delete an element that uses a component it works, but I get the exact same error.

error: Undefined binding(s) detected while compiling WHERE. Undefined column(s): query [t0.id]: where "t0".."id" =?
Error: Undefined binding(s) found while compiling WHERE. Undefined column(s): query [t0.id]: where "t0".."id" =?
    at QueryCompiler_PG.toSQL (...../node_modules/knex/li ....

Upgrading to v4.5.1 fixed the issue.

Can you check for me if this issue still exists in 4.5.6 if it does please make a issue on the strapi repo with reproduction staps