-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
find
with multiple WHERE
clauses where one is invalid generates invalid SQL
#6465
Comments
Suggestions on what to do in case 1? On case 2 I think we should throw an exception when building that query - it obviously does not work. |
@imnotjames I'd imagine throw an error as well. In all the cases that it happened to me, I'd prefer to know the error and where it came from instead of spending the first 5 minutes of debugging on trying to find where it is |
|
For case 2.. oof. Ok, so - right now TypeORM is pretty flexible on allowing you to include data that's not really.. ideal. Such as invalid fields. The right thing to do for consistency is to silently ignore the field.. but.. oof.. that hurts. I'm going to update a few bits of this issue to make it more reflect that case 2 piece |
find
with multiple WHERE
clauses where one is invalid generates invalid SQL
It looks like this may have been fixed around when you opened this! I can no longer replicate this using the example you gave. When trying to it emits the following error:
To note, the test I created follows.
|
Duplicate of #3416 |
Closing because case 2 is also a duplicate. If you're still seeing this problem please update in that issue with how to replicate. |
Issue type:
[ ] question
[X] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[X]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
cockroachdb
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[ ]
latest
[ ]
@next
[X]
0.2.22
(or put your version here)Hiding first case as it's a duplicate of #2195
CASE 1:
Suppose you have an array of IDs and you want to fetch entries with those IDs. Array can be empty sometimes due to your app's logic. Code sample:
With debug logging enabled this is the query you will see:
... which will fail due to syntax error.
CASE 2:
You have a table for which users might submit a search string. That string needs to be matched against the fields
amount: number
andcustomerSummary: { name: string }
. Because theLike
filter is always considered a string, we start getting TS errors about wrong types, which forces us to add a bunch of//@ts-ignore
like this:This would produce a query:
All good, But! If you make a typo in let's say,
customerSumary
, Typescript will not tell you since you had to tell it to ignore types on that line. In that case instead of TypeORM throwing an error (ideally) or at least ignoring the condition, you get a query like this:So obviously this is a syntax error. Interstingly, it does obviously check for field validity, but doesn't bother letting me know instead just omitting it.
The text was updated successfully, but these errors were encountered: