-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
Description
Update vs Insert Behavior Inconsistencies
This meta-issue tracks inconsistencies in how Knex processes values differently between update()
and insert()
operations. These inconsistencies make it difficult to write code that works predictably across both operations.
Core Issues
Undefined Value Handling
- Different treatment of undefined values for update vs. insert #5488 - Different treatment of undefined values for update vs. insert
update()
: undefined values are ignored (columns omitted from query)insert()
: undefined values cause "table has no column named X" errors- Database: SQLite, PostgreSQL
- Expected: Consistent behavior - both should either ignore or error
Object Serialization
- Updating a column with an object throws an error, but inserting the same object into the column does not. #5450 - Updating a column with an object throws error, but inserting the same object doesn't
insert()
: objects are automatically serialized to JSON stringsupdate()
: objects cause "SQLite3 can only bind numbers, strings..." errors- Database: SQLite (better-sqlite3)
- Expected: Consistent serialization behavior
Impact
These inconsistencies force developers to:
- Handle undefined values differently depending on operation type
- Manually serialize objects for updates but not for inserts
- Write defensive code with operation-specific logic
Root Cause
The update()
and insert()
code paths have diverged in their value processing logic. They should share common validation and transformation logic to ensure consistent behavior.
Proposed Solution
Unify value processing logic between insert and update operations:
- Consistent undefined handling (either always ignore or always error)
- Consistent object serialization (apply same rules for both operations)
- Shared validation and transformation pipeline
Related Work
This is separate from but related to:
- Type coercion issues (different META)
- Database-specific value handling (tracked in respective database METAs)