Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update vs Insert Behavior Inconsistencies #6294

@mercmobily

Description

@mercmobily

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

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:

  1. Consistent undefined handling (either always ignore or always error)
  2. Consistent object serialization (apply same rules for both operations)
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions