{"record":{"id":"899aa77d0c7a5095","repo":"SeaQL/sea-orm","slug":"already-checked-arity-899aa7","errorCode":null,"errorMessage":"Already checked arity","messagePattern":"Already checked arity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/base_entity.rs","lineNumber":344,"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":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/base_entity.rs#L326-L362","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// check primary key arity matches the actual primary key column count\nlet declared = <<Entity::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY;\nassert_eq!(declared as usize, Entity::PrimaryKey::iter().count());","typeGuard":"fn primary_key_consistent<E: EntityTrait>() -> bool {\n    <<E::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY as usize\n        == E::PrimaryKey::iter().count()\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["primary-key","panic","code-generation","internal-invariant"],"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"}