{"record":{"id":"06764886cff518d6","repo":"SeaQL/sea-orm","slug":"already-checked-arity-067648","errorCode":null,"errorMessage":"Already checked arity","messagePattern":"Already checked arity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/entity/model.rs","lineNumber":90,"sourceCode":"        find_linked_recursive(initial_query, link)\n    }\n\n    /// Delete a model\n    async fn delete<'a, A, C>(self, db: &'a C) -> Result<DeleteResult, DbErr>\n    where\n        Self: IntoActiveModel<A>,\n        C: ConnectionTrait,\n        A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a,\n    {\n        self.into_active_model().delete(db).await\n    }\n\n    /// Get the primary key value of the Model\n    fn get_primary_key_value(&self) -> ValueTuple {\n        let mut cols = <Self::Entity as EntityTrait>::PrimaryKey::iter();\n        macro_rules! next {\n            () => {\n                self.get(cols.next().expect(\"Already checked arity\").into_column())\n            };\n        }\n        match <<<Self::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType as PrimaryKeyArity>::ARITY {\n            1 => {\n                let s1 = next!();\n                ValueTuple::One(s1)\n            }\n            2 => {\n                let s1 = next!();\n                let s2 = next!();\n                ValueTuple::Two(s1, s2)\n            }\n            3 => {\n                let s1 = next!();\n                let s2 = next!();\n                let s3 = next!();\n                ValueTuple::Three(s1, s2, s3)\n            }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/entity/model.rs#L72-L108","documentation":"`get_primary_key_value` in `src/entity/model.rs:90` iterates the entity's primary-key columns and calls `cols.next().expect(\"Already checked arity\")` inside a `next!` macro. The `match` on `PrimaryKeyArity::ARITY` guarantees the iterator has exactly that many items, so the expect documents an internal invariant. It only fires if the entity's `PrimaryKeyTrait`/`PrimaryKeyArity` impl is inconsistent (declared arity does not match the actual number of key columns).","triggerScenarios":"Calling `get_primary_key_value()` (directly or via save/delete/update of a `Model`) on an entity whose `PrimaryKey::iter()` yields fewer columns than `PrimaryKeyArity::ARITY` declares — e.g. a hand-written or code-generated broken primary-key impl.","commonSituations":"Hand-rolled entity definitions, entities generated by an outdated `sea-orm- io` version, or macro-generated code where the PK columns and arity desync after editing the model.","solutions":["Regenerate or correct the entity so `PrimaryKey` enum variants match the declared `PrimaryKeyArity` (SeaORM 2.0 new entity format).","Update `sea-orm-io` to the version matching your `sea-orm` version so generated arity is correct.","Verify the `#[sea_orm(primary_key)]` attribute is present on the PK field(s) of the model."],"exampleFix":"// before (hand-written, arity says 1 but two pk columns)\nimpl PrimaryKeyTrait for PrimaryKey { type ValueType = i32; type Arity = PrimaryKeyArity::One; }\n// after (regenerated entity matching model)\n#[sea_orm(primary_key)]\npub id: i32,\n// PrimaryKey::Id with PrimaryKeyArity::One\n","handlingStrategy":"type-guard","validationCode":"// Check the entity's declared PK arity matches the key fields at startup\nlet arity = <<MyEntity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::ARITY;\ndebug_assert_eq!(arity, <MyEntity::PrimaryKey as PrimaryKeyTrait>::iter().count() as usize);","typeGuard":"fn pk_arity_matches<E: EntityTrait>() -> bool {\n    <<E as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::ARITY\n        == <E::PrimaryKey as PrimaryKeyTrait>::iter().count()\n}","tryCatchPattern":null,"preventionTips":["Always generate entities with sea-orm-io instead of hand-writing PrimaryKey impls.","Keep the CLI and sea-orm crate versions in sync.","Run entity compile/round-trip tests after editing primary keys."],"tags":["primary-key","internal-invariant","entity-definition"],"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"}