Problem
The model macro accepts contradictory or unsafe key declarations:
#[key] Option<T> compiles even though a PostgreSQL primary key is always non-null.
by_id(None) and active update/delete through a nullable key are generated.
#[autoincrement] without #[key] compiles despite inconsistent generated insert behavior.
- Floating-point
#[key] fields use ordinary Rust equality during relation grouping. Rust considers NaN != NaN, while PostgreSQL deliberately treats floating-point NaN values as equal for indexes and ordering.
A nullable pseudo-key can be especially unsafe when the underlying column is not actually unique: eq(None) becomes IS NULL, so generated update/delete operations may match multiple rows.
Expected behavior
- Reject nullable
#[key] fields during macro expansion.
- Reject
#[autoincrement] unless the same field is a key.
- Either reject
f32/f64 key fields or implement key equality that matches PostgreSQL; rejection is the simpler default.
- Add focused compile-fail tests for invalid annotations.
- Keep nullable foreign keys supported; this restriction applies only to fields marked
#[key].
PostgreSQL primary keys are unique and non-null
Problem
The model macro accepts contradictory or unsafe key declarations:
#[key] Option<T>compiles even though a PostgreSQL primary key is always non-null.by_id(None)and active update/delete through a nullable key are generated.#[autoincrement]without#[key]compiles despite inconsistent generated insert behavior.#[key]fields use ordinary Rust equality during relation grouping. Rust considersNaN != NaN, while PostgreSQL deliberately treats floating-pointNaNvalues as equal for indexes and ordering.A nullable pseudo-key can be especially unsafe when the underlying column is not actually unique:
eq(None)becomesIS NULL, so generated update/delete operations may match multiple rows.Expected behavior
#[key]fields during macro expansion.#[autoincrement]unless the same field is a key.f32/f64key fields or implement key equality that matches PostgreSQL; rejection is the simpler default.#[key].PostgreSQL primary keys are unique and non-null