SeaQL/sea-orm · error
Already checked arity
Error message
Already checked arity
What it means
`primary_key_identity` builds the primary key Identity by iterating PrimaryKey columns, after asserting arity via `PrimaryKeyArity::ARITY`. The macro's `.expect("Already checked arity")` (src/entity/base_entity.rs:344) fires if the iterator is exhausted despite the declared ARITY — i.e. the PrimaryKey enum and its ARITY disagree.
Source
Thrown at src/entity/base_entity.rs:344
let mut keys = Self::PrimaryKey::iter();
for v in values.into().into_value_tuple() {
if let Some(key) = keys.next() {
let col = key.into_column();
select = select.filter(col.eq(v));
} else {
unreachable!("primary key arity mismatch");
}
}
select
}
/// Get primary key as Identity
fn primary_key_identity() -> Identity {
let mut cols = Self::PrimaryKey::iter();
macro_rules! next {
() => {
cols.next()
.expect("Already checked arity")
.into_column()
.as_column_ref()
.1
};
}
match <<Self::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {
1 => {
let s1 = next!();
Identity::Unary(s1)
}
2 => {
let s1 = next!();
let s2 = next!();
Identity::Binary(s1, s2)
}
3 => {
let s1 = next!();
let s2 = next!();View on GitHub (pinned to e29bcd1b41)
Solutions
- Regenerate entities with sea-orm-cli so derive macros produce consistent PrimaryKey and arity.
- Remove manual PrimaryKeyTrait impls and rely on DeriveEntityModel.
- Ensure each `#[sea_orm(primary_key)]` column is kept in sync when altering schemas.
- Report to SeaORM if reproducible with purely generated code.
Defensive patterns
Strategy: type-guard
Validate before calling
// check primary key arity matches the actual primary key column count let declared = <<Entity::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY; assert_eq!(declared as usize, Entity::PrimaryKey::iter().count());
Type guard
fn primary_key_consistent<E: EntityTrait>() -> bool {
<<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY as usize
== E::PrimaryKey::iter().count()
} Prevention
- Never hand-implement PrimaryKeyTrait; rely on DeriveEntityModel
- Regenerate entities with sea-orm-cli after key changes
- Pin SeaORM versions so generated code matches the runtime macros
When it happens
Trigger: An entity whose PrimaryKey definition's ValueType arity (1 or composite) does not match the number of `#[sea_orm(primary_key)]` columns — typically only via macro/codegen bugs or hand-rolled PrimaryKeyTrait implementations.
Common situations: Manually implementing PrimaryKeyTrait instead of deriving it; editing generated entities to add/remove primary key columns without updating arity; SeaORM version upgrades where generated code differs.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
AI-assisted analysis of SeaQL/sea-orm@e29bcd1b41 (2026-09-10).
Data as JSON: /api/errors/899aa77d0c7a5095.
Report an issue: GitHub.