question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strange "Undefined binding(s) detected" error message

See original GitHub issue

Environment

Knex version: 0.20.10 Database + version: Postgres 12

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do
knex.raw("?", [
  knex.insert({ id: "b", fields: { a: undefined } }).into("test"),
])
  1. Error message

Error: Undefined binding(s) detected for keys [] when compiling RAW query: insert into "test" ("fields", "id") values (?, ?)

This error message is puzzling. Undefined keys are not printed.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
genadiscommented, Jul 3, 2020

I believe this https://github.com/knex/knex/issues/3548 is related

1reaction
kibertoadcommented, Mar 31, 2020

@thekuom It’s less straightforward than I though, due to rather cluttered logic around this place, and a peculiar way raw insert is being done in original case. If you have some time to dig deeper, here’s a test case you can use for reproducing the issue:

const Knex = require('../../../lib/index');
const { expect } = require('chai');

describe('querybuilder', () => {
  let knex;
  beforeEach(() => {
      knex = Knex({
        client: 'sqlite',
        connection: ':memory:',
      });
    },
  );

  it('should throw an informative error on undefined binding', async () => {
    try {
      await knex.raw('?', [
        knex.insert({ id: 'b', fields: { a: undefined } }).into('test'),
      ]);
    } catch (err) {
      expect(err.message).eql('Undefined binding(s) detected for keys [0] when compiling RAW query: insert into `test` (`fields`, `id`) values (?, ?)');
    }
  });
});

@leventov For curiosity sake, why you building query in a such complex way?

Both of these should already work properly:

knex.raw('?', [undefined])

or

knex.raw(':field', { field: undefined })

Does your query work correctly when value is not undefined?

Read more comments on GitHub >

github_iconTop Results From Across the Web

knex.js - Error: Undefined binding(s) detected when compiling ...
Error: Undefined binding(s) detected when compiling SELECT from Bookshelf.js save() · It happens when one of the bindings values is undefined.
Read more >
Parent/Child setup : Error: Undefined binding(s) detected ...
Error : Undefined binding(s) detected when compiling WHERE. Undefined column(s): [recruits_emails.recruitID] query: where recruits_emails .
Read more >
Undefined binding(s) detected when using ...
I found this by adding a log.trace('findOne') into node_modules/knex/lib/query/querycompiler.js line 109 after if (this._undefinedInWhereClause) ...
Read more >
Custom Query - Undefined binding(s) detected for keys
Hi, I'm trying to write a custom query to “Insert into” a SQL table. However, I'm having trouble getting the parameters to work...
Read more >
Python bindings - Nsnam - NS-3
ImportError : undefined symbol ... This can be fixed by finding the method that exists in the class declaration but that is not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found