{"record":{"id":"7bd7a8afdca91953","repo":"SeaQL/sea-orm","slug":"trait-bound-ensured-arity-7bd7a8","errorCode":null,"errorMessage":"trait bound ensured arity","messagePattern":"trait bound ensured arity","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/delete.rs","lineNumber":212,"sourceCode":"    ///\n    /// # Panics\n    ///\n    /// Should not panic.\n    pub fn filter_by_ids<I>(mut self, values: I) -> Self\n    where\n        I: IntoIterator<Item = <E::PrimaryKey as PrimaryKeyTrait>::ValueType>,\n    {\n        self.query.cond_where(\n            column_tuple_in_condition(\n                &E::default().table_ref(),\n                &E::primary_key_identity(),\n                &values\n                    .into_iter()\n                    .map(|v| v.into_value_tuple())\n                    .collect::<Vec<_>>(),\n                DbBackend::Sqlite,\n            )\n            .expect(\"trait bound ensured arity\"),\n        );\n        self\n    }\n\n    #[doc(hidden)]\n    /// # Panics\n    ///\n    /// Panic if `ValueTuple` arity does not match primary key\n    pub fn filter_by_value_tuples(mut self, values: &[ValueTuple], db_backend: DbBackend) -> Self {\n        self.query.cond_where(\n            column_tuple_in_condition(\n                &E::default().table_ref(),\n                &E::primary_key_identity(),\n                values,\n                db_backend,\n            )\n            .expect(\"\"),\n        );","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/SeaQL/sea-orm/blob/e29bcd1b417c41a553b386fe94511d7c64a1c8ec/src/query/delete.rs#L194-L230","documentation":"`DeleteOne::filter_by_ids` in `src/query/delete.rs:212` validates that the primary-key value tuples it just built match the entity's declared `PrimaryKeyArity`, and `.expect(\"trait bound ensured arity\")` asserts this always holds. The trait bound on the method's generics is supposed to guarantee tuple/value arity agreement, so the panic signals a violated compile-time contract at runtime — typically from empty or malformed input value types.","triggerScenarios":"Calling `filter_by_ids` with values whose `into_value_tuple()` output arity does not match the entity's `PrimaryKeyArity` — e.g. passing a composite-key tuple to a single-key entity or vice versa through dynamic/generic code.","commonSituations":"Generic helpers that delete by ID across differently shaped entities; refactors that changed a table from single to composite primary key while callers still pass scalar ids; `DeriveValueType` wrappers altering tuple shape.","solutions":["Pass primary-key values of the exact entity's `PrimaryKey::ValueType` (tuple of the right arity for composite keys).","Update all generic call sites after changing a table's primary-key structure.","Let the compiler infer types via `<Entity as PrimaryKeyTrait>::ValueType` instead of hardcoding `i32`/tuples."],"exampleFix":"// before\ndelete_one_my_entity.filter_by_ids(vec![1]) // composite-key entity (id, org_id)\n// after\nuse sea_orm::entity::prelude::*;\nfilter_by_ids(vec![(1, 42)]) // tuple matching PrimaryKeyArity::Two\n","handlingStrategy":"validation","validationCode":"// Verify value arity matches PK arity before calling\nlet arity = <<E as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::ARITY;\nassert!(!ids.is_empty());\ndebug_assert_eq!(ids.len(), 1); // for single-key entities using into_value_tuple","typeGuard":"fn ids_match_pk_arity<E: EntityTrait>(vals: &[ValueTuple]) -> bool {\n    vals.iter().all(|v| v.arity() == <<E as EntityTrait>::PrimaryKey as PrimaryKeyTrait>::ValueType::ARITY)\n}","tryCatchPattern":null,"preventionTips":["Type id collections as <E::PrimaryKey as PrimaryKeyTrait>::ValueType, not raw i32/Vec.","Update all delete-by-id call sites when a table gains composite keys.","Add unit tests for delete_by_ids on every entity with composite PKs."],"tags":["primary-key","arity","delete"],"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"}