{"record":{"id":"4737240010355e58","repo":"SeaQL/sea-orm","slug":"already-checked-arity","errorCode":null,"errorMessage":"Already checked arity","messagePattern":"Already checked arity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sea-orm-sync/src/entity/base_entity.rs","lineNumber":341,"sourceCode":"        let mut keys = Self::PrimaryKey::iter();\n        for v in values.into().into_value_tuple() {\n            if let Some(key) = keys.next() {\n                let col = key.into_column();\n                select = select.filter(col.eq(v));\n            } else {\n                unreachable!(\"primary key arity mismatch\");\n            }\n        }\n        select\n    }\n\n    /// Get primary key as Identity\n    fn primary_key_identity() -> Identity {\n        let mut cols = Self::PrimaryKey::iter();\n        macro_rules! next {\n            () => {\n                cols.next()\n                    .expect(\"Already checked arity\")\n                    .into_column()\n                    .as_column_ref()\n                    .1\n            };\n        }\n        match <<Self::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {\n            1 => {\n                let s1 = next!();\n                Identity::Unary(s1)\n            }\n            2 => {\n                let s1 = next!();\n                let s2 = next!();\n                Identity::Binary(s1, s2)\n            }\n            3 => {\n                let s1 = next!();\n                let s2 = next!();","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/entity/base_entity.rs#L323-L359","documentation":"This panic is thrown in `EntityTrait::primary_key_identity()` when the primary key iterator returns `None` even though the `PrimaryKeyArity` trait declared the key has more columns. It is an internal invariant: the compile-time ARITY constant must exactly match the number of columns in the `PrimaryKey` enum. The message 'Already checked arity' reflects that the match on ARITY was supposed to guarantee `cols.next()` succeeds that many times.","triggerScenarios":"Occurs when a hand-written entity declares a `PrimaryKey` enum whose number of variants disagrees with the `PrimaryKeyArity` implementation for its `ValueType` (e.g. composite key misdeclared as single-column), or when the PrimaryKey iter() impl and the ARITY constant are inconsistent.","commonSituations":"Developers manually writing entity definitions instead of using sea-orm-cli codegen, refactoring a table from a single-column to a composite primary key without updating `ValueType` to a tuple, or upgrading SeaORM versions where arity derives changed.","solutions":["Regenerate the entity with sea-orm-cli so the PrimaryKey enum and its ValueType arity match the table schema.","If hand-written, make the PrimaryKey ValueType match the column count: one column uses the id type, composite keys use a tuple like (i32, i32).","Ensure `PrimaryKeyTrait` is implemented via `#[derive(Iden)]`/DerivePrimaryKey so ARITY is derived, not manually specified with the wrong number."],"exampleFix":"// before\npub enum PrimaryKey { Id } // but ValueType declared as (i32, i32)\n// after\n#[derive(EnumIter, DerivePrimaryKey)]\npub enum PrimaryKey { Id, Version }\n// ValueType is derived as (i32, i32) matching two columns","handlingStrategy":"validation","validationCode":"let arity = <MyEntity::PrimaryKey as PrimaryKeyTrait>::ValueType::arity();\nlet col_count = MyEntity::PrimaryKey::iter().count();\nassert_eq!(arity, col_count, \"PrimaryKey enum/ValueType arity mismatch\");","typeGuard":"fn has_consistent_pk<E: EntityTrait>() -> bool {\n    E::PrimaryKey::iter().count() == <<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY\n}","tryCatchPattern":null,"preventionTips":["Always generate entities with sea-orm-cli instead of hand-writing PrimaryKey definitions.","Keep ValueType tuple length in sync with composite key columns.","Add a compile-time/entity test asserting arity consistency after schema changes."],"tags":["panic","internal-invariant","primary-key","sea-orm"],"backgroundTag":"internal-invariant-violation","analyzedSha":"e29bcd1b417c41a553b386fe94511d7c64a1c8ec","analyzedAt":"2026-09-10T11:31:52.468Z","contentChangedAt":"2026-09-10T11:31:52.468Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}