brianc / node-pg-native

Native (C/C++) bindings to PostgreSQL with sync and async options.
247 stars 44 forks source link

Unhandled rejection #54

Closed sibedge closed 7 years ago

sibedge commented 7 years ago

I keep getting the following error in my tests after upgrading to the latest branch 6.3.0 of the main driver:

Unhandled rejection TypeError: this.values.map is not a function
    at NativeQuery.submit (...\node_modules\pg\lib\native\query.js:145:28)
    at Client._pulseQueryQueue (...\node_modules\pg\lib\native\index.js:210:9)
    at Client.query (...\node_modules\pg\lib\native\index.js:169:8)

Previously all tests were running against v5.1 of the driver, plus the latest pg-native, and the error never occurred.


brianc commented 7 years ago

Can you include a sample of code that produces the issue? I can't help without seeing some code that's causing a problem. You're likely passing something other than an array as the values object to client.query('foo', ['bar']) but all I can do is guess w/o seeing what is causing the issue.

sibedge commented 7 years ago

@brianc you were right, it has to do with passing in a value instead of an array.

But consider the following code:

var pg = require('pg');//.native;
var pool = new pg.Pool(cn);

pool.connect((err, client, done) => {
    if (err) {
        console.log('ERROR:', err);
        return;
    }
    client.query('select * from findUser(1)', 1, (err, result) => {
        if (err) {
            console.log('ERROR:', err);
        } else {
            console.log('DATA:', result.rows);
        }
        done();
    });
});

It works with the JavaScript bindings, as it happily ignores the parameters that are not needed, but just as we uncomment the .native part there, we get that error I reported earlier.

So there, at least, a discrepancy in how the driver handles it in the Native Bindings.

brianc commented 7 years ago

Thanks for pointing that out! Yeah the JavaScript bindings should probably be brought up to throw an error or have the query error out if you pass anything other than an array as the value to the values parameter. Silent ignore/failure of invalid method args kinda gross, I think. What do you think?

sibedge commented 7 years ago

For someone who tried to switch from JavaScript to the Native bindings and got stuck with some existing tests, I'd say consistency is the most valuable aspect here :smile:

brianc commented 7 years ago

👍 I hear ya. I'll make it throw a friendly error in both native & pure JS if you don't pass an array for values. 😄

brianc commented 7 years ago

this will be fixed in pg7.0 - both native and js driver will have the query callback with an error if you pass anything other than an array as the values argument to a parameterized query.

https://github.com/brianc/node-postgres/pull/1366

Thanks for your patience!