Join GitHub today
Uint8Array data (e.g. Postgres "bytea" type) erroneously considered "undefined" by recent 0.11.7 update. #1601
Currently using bookshelf in a project. Upon update to knex v0.11.7, noticed that an update was failing with error "Undefined binding(s) detected when compiling RAW query: ...".
I understand that any data field with value undefined will cause this type of error.
I looked into my code and found that as part of my query, no data to be bound was "undefined". Digging deeper I found that input values of type "Uint8Array" were failing the deep inspection test on data to be bound in
The Uint8Array was failing the check because it fails the lodash "isArray" check, and so is evaluated as an object; it has an internal property "parent" which was undefined. It should be noted that data returned from "pg" for Postgres "bytea" columns are passed back to knex as a "Uint8Array". In my use case, I was updating a record with data originally passed back from a previous query. Thus my value was not "undefined"
To fix this case, I propose that the lodash "isTypedArray" check also be used alongside the "isArray" check. Then a Uint8Array will be treated as an Array (with index 0-n and property length) thus not being considered "undefined" when it is not truely so:
Please advise if this simple proposal is acceptable, if you have any additional feedback or approaches. I hope this change can be merged into the knex code base for the next release.
@mashaalmemon nice catch. Actually it doesn't appear possible for a typed array to contain
new Uint8Array([undefined]); // -> 
So there's no need to check the elements if a typed array is provided. You can simplify this check to:
if (isTypedArray(mixed)) return false;