Skip to content

fix(sql): #[auto] fields are inserted with Default::default(), clobbering DB defaults #180

Description

@RAprogramm

Generated create/create_many/upsert include #[auto] fields in the INSERT column list, and From<CreateRequest> fills them with Default::default(). For created_at: DateTime<Utc> that means an explicit 1970-01-01 is written, silently overriding the table's DEFAULT now().

Expected

#[auto] means "the database generates this value": auto fields must be excluded from the INSERT column list entirely so column defaults apply, and the persisted values must come back via RETURNING (the default returning = "full" already refetches the row).

Scope

  • Insert column list / placeholders / Insertable struct / bindings skip #[auto] fields (create, create_many, upsert)
  • returning = "id"/"none"/custom keep returning the pre-built entity — document that auto fields are placeholders there
  • Unit tests for column-list shape; trybuild pass case asserting the generated INSERT omits auto columns

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: highImportant for adoption

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions