{"record":{"id":"c4ea3d3abb598e88","repo":"dani-garcia/vaultwarden","slug":"error-loading-users-collections","errorCode":null,"errorMessage":"Error loading users_collections","messagePattern":"Error loading users_collections","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/db/models/collection.rs","lineNumber":681,"sourceCode":"        .await\n    }\n}\n\n/// Database methods\nimpl CollectionUser {\n    pub async fn find_by_organization_and_user_uuid(\n        org_uuid: &OrganizationId,\n        user_uuid: &UserId,\n        conn: &DbConn,\n    ) -> Vec<Self> {\n        conn.run(move |conn| {\n            users_collections::table\n                .filter(users_collections::user_uuid.eq(user_uuid))\n                .inner_join(collections::table.on(collections::uuid.eq(users_collections::collection_uuid)))\n                .filter(collections::org_uuid.eq(org_uuid))\n                .select(users_collections::all_columns)\n                .load::<Self>(conn)\n                .expect(\"Error loading users_collections\")\n        })\n        .await\n    }\n\n    pub async fn find_by_organization_swap_user_uuid_with_member_uuid(\n        org_uuid: &OrganizationId,\n        conn: &DbConn,\n    ) -> Vec<CollectionMembership> {\n        let col_users = conn\n            .run(move |conn| {\n                users_collections::table\n                    .inner_join(collections::table.on(collections::uuid.eq(users_collections::collection_uuid)))\n                    .filter(collections::org_uuid.eq(org_uuid))\n                    .inner_join(\n                        users_organizations::table.on(users_organizations::user_uuid.eq(users_collections::user_uuid)),\n                    )\n                    .filter(users_organizations::org_uuid.eq(org_uuid))\n                    .select((","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/dani-garcia/vaultwarden/blob/cc67d644f62605cb46f4d16c4a2eed1a861cc8bb/src/db/models/collection.rs#L663-L699","documentation":"Panic from `expect` when `CollectionUser::find_by_organization_and_user_uuid` fails to load users_collections rows (per-user collection permissions) for a user's org memberships, joined with collections filtered by org. Query execution or deserialization failure panics; zero matching rows does not.","triggerScenarios":"Calling `find_by_organization_and_user_uuid` when DB connectivity fails, `users_collections` table schema mismatches (e.g. missing `manage` column after unmigrated upgrade), or join to collections fails at the SQL level.","commonSituations":"Upgrading without running the migration that added the `manage` column to users_collections; DB connection loss; manual schema edits; corrupted SQLite file.","solutions":["Run migrations so users_collections matches the model (including the manage column)","Log the underlying diesel error to diagnose","Verify DB connectivity and credentials","Fix users_collections column set/types if manually altered","Restore the database from a backup"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify users_collections has the expected columns (SQLite)\nlet ok = conn.run(|c| diesel::select(diesel::dsl::sql::<diesel::sql_types::Bool>(\n    \"SELECT EXISTS (SELECT 1 FROM pragma_table_info('users_collections') WHERE name='manage')\"\n)).load::<bool>(c)).await.unwrap_or(vec![false]).into_iter().next().unwrap_or(false);\nassert!(ok, \"users_collections.manage missing; run migrations\");","typeGuard":null,"tryCatchPattern":"let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(async {\n    CollectionUser::find_by_organization_and_user_uuid(&org_uuid, &user_uuid, &conn).await\n}));\nif r.is_err() { log::error!(\"users_collections load panicked; schema/migrations mismatch likely\"); }","preventionTips":["Always run the migrations adding newer permission columns (manage)","Diff DB schema against models after upgrades","Probe DB health at startup","Avoid partial/manual migrations","Backup the DB before upgrading"],"tags":["rust","diesel","database","panic","permissions"],"backgroundTag":"database-query-failed","analyzedSha":"cc67d644f62605cb46f4d16c4a2eed1a861cc8bb","analyzedAt":"2026-09-19T08:28:46.370Z","contentChangedAt":"2026-09-19T08:28:46.370Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}