{"record":{"id":"7e0acc82efb59959","repo":"SeaQL/sea-orm","slug":"already-checked-arity-7e0acc","errorCode":null,"errorMessage":"Already checked arity","messagePattern":"Already checked arity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sea-orm-sync/src/entity/model.rs","lineNumber":89,"sourceCode":"        find_linked_recursive(initial_query, link)\n    }\n\n    /// Delete a model\n    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 + 'a,\n    {\n        self.into_active_model().delete(db)\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":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/sea-orm-sync/src/entity/model.rs#L71-L107","documentation":"`ModelTrait::get_primary_key_value()` iterates the entity's `PrimaryKey` columns and expects exactly as many columns as `PrimaryKeyArity::ARITY` declares. The panic fires when the iterator runs dry before ARITY is satisfied, i.e. the compile-time arity constant disagrees with the actual number of primary key column variants.","triggerScenarios":"Calling `.get_primary_key_value()` (directly or via save/delete helpers) on a Model whose entity's PrimaryKey enum has fewer variants than the declared ARITY, typically due to a hand-edited or stale entity definition.","commonSituations":"Migrations that added a primary key column while the generated entity was not refreshed; copying an entity module and editing columns without regenerating; composite key tables modeled with a single-column ValueType.","solutions":["Regenerate the entity from the database schema with sea-orm-cli.","Align the PrimaryKey enum variants and ValueType tuple length (1, 2, or 3 columns).","Run entity unit tests after any schema change to catch arity drift before runtime."],"exampleFix":"// before\n#[derive(EnumIter, DerivePrimaryKey)]\npub enum PrimaryKey { Id } // table actually has (Id, TenantId)\n// after\n#[derive(EnumIter, DerivePrimaryKey)]\npub enum PrimaryKey { Id, TenantId }","handlingStrategy":"validation","validationCode":"let col_count = <MyEntity as EntityTrait>::PrimaryKey::iter().count();\nlet arity = <<MyEntity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::arity();\nassert_eq!(col_count, arity, \"entity primary key arity drift\");","typeGuard":"fn model_pk_consistent<M: ModelTrait>() -> bool {\n    <<M::Entity as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::arity()\n        == <M::Entity as EntityTrait>::PrimaryKey::iter().count()\n}","tryCatchPattern":null,"preventionTips":["Never hand-edit generated entity files; regenerate after migrations.","Keep PrimaryKey enum variants in sync with the actual table's key columns.","CI-check entity definitions against the live schema."],"tags":["panic","primary-key","model","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"}