New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search error #17946
Comments
@lericol just to confirm, are you using PostgreSQL as the database? This seems very much like #15809. It looks to be a rather odd bug. I can confirm it happens in PostgreSQL, but not in MySQL. Exact reproduction steps
FindingsIt seems like the "issue" precisely happens with this line: directus/api/src/utils/apply-query.ts Line 762 in 13a720b
as What's particularly odd is both syntax actually generates the exact same SQL query, at least from what I've found. Here's a sample hooks extension to further illustrate it: module.exports = ({ init }, { database: knex }) => {
init('app.before', async () => {
const collection = 'test';
const name = 'id';
const number = 710406684325;
const failedQuery = knex.from(collection).where({ [`${collection}.${name}`]: number }); // this is the same object syntax as apply-query.ts line 763
// using number as the 3rd binding also doesn't work in Postgres, but works in MySQL
// .whereRaw(`??.?? = ?`, [collection, name, number]);
const successfulQuery = knex.from(collection).whereRaw(`??.?? = ${number}`, [collection, name]);
// both generates the exact same query.
// PostgreSQL: 'select * from "test" where "test"."id" = 710406684325'
// MySQL: 'select * from `test` where `test`.`id` = 710406684325'
console.log({ rawFailedQuery: failedQuery.toString() });
console.log({ rawSuccessfulQuery: successfulQuery.toString() });
// somehow for failedQuery, `710406684325` is turned into string `"710406684325"` via pg driver
failedQuery.then((r) => console.log({ failedQuery: r })).catch((e) => console.error(e));
successfulQuery.then((r) => console.log({ successfulQuery: r })).catch((e) => console.error(e));
});
}; Testing with
With the information at hand, I can only assume it's something to do with the |
Yes, PostgreSQL |
After further investigating here are my findings , the way knex is parsing whereRaw and passing it to the PG driver is diffrent then the way it's pass the where so i had a collection called currencies , and a int field and i init a connection with the pg library directly
using whereRaw and orWhereRaw is the equivalent of the following code , it's will ignore the error how ever the results are actually always 0 row unless there is a diffrent orWhereRaw , so it's not really a successfulQuery , more like one that ignore errors.
in the other hand using where ( orWhere ) is the equivalent of the following code , the code will perform checks internally using the ( libpq library ) , and show the out of range error
so using this.orWhereRaw instead of this.orWhere will be the solution |
Based on #17955 (review) a potential fix addressing this issue should meet the following criteria:
|
Would be nice to see a fix for this I'd love to be able to use a barcode scanner on the search field :) |
Describe the Bug
You have table (collection): id (int), params (string)
If you try to find big value in this table (collection) - you catch the error
To Reproduce
create collection with id (int) and field test (string)
try to find big value in this table (collection) - you catch the error
Hosting Strategy
Self-Hosted (Docker Image)
The text was updated successfully, but these errors were encountered: