ExpressionBuilder
allows invalid fields in update/set, causing runtime failures
#1299
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
typescript
Related to Typescript
Most set/update update styles in Kysely work as expected, disallowing extraneous properties not present in the schema, as otherwise the queries will fail when executed.
Unfortunately, there's one case that is quite natural to use, which dangerously doesn't check for this: using an ExpressionBuilder function which returns an object -
Full example: https://kyse.link/klyC9
In the above example in the
onConflict
clause, thefirst_name
property is required, and as expected, if no valid fields are present, then the query fails.However, once at least one other valid property is in the object, you can add any other extraneous properties and they won't fail typechecking. This is incorrect and will lead to runtime query failures (my team uses this pattern extensively, and were just bitten by it 😢 ).
The example above is the exact case that my team ran into, but it looks like it also applies to cases like
set((eb) => ({ ... })
.To mitigate this issue, you can pass the object directly to
doUpdateSet
instead, but you'll have to use a(eb) =>
closure in every field instead, which makes it the much less appealing option (for example when doing masseb.ref("excluded.field"
).The text was updated successfully, but these errors were encountered: