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.
… such as Uint8Arrays are treated as "Arrays" vs as "Objects". For example, pgsql "bytea" type column data is passed back as Uint8Arrays by the node pgsql driver "pg" and without this modification, such data will fail the "containsUndefined" test.
@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;
… such as Uint8Arrays are automatically treated as "not undefined" (vs as "Array" which will result in unecessary testing of Array contents). For example, pgsql "bytea" type column data is passed back as Uint8Arrays by the node pgsql driver "pg" and without this modification, such data will fail the "containsUndefined" test with previous implementation.
* master: release 0.11.10 Prep for release Add CHANGELOG.md (#1615) Added padding to avoid header sticking to the example usage. Updated docs to note schema builder is getter. Remove unused files Uint8Array data (e.g. Postgres "bytea" type) erroneously considered "undefined" by recent 0.11.7 update. (#1601) Revert "[docs] document multi-column order-by" [docs] document multi-column order-by MSSQL columnInfo() had hard coded schema name (#1585)