{"record":{"id":"bb0f6c235b8e4c16","repo":"nextcloud/server","slug":"unable-to-fetch-principal-for-user-user","errorCode":null,"errorMessage":"Unable to fetch principal for user $user ","messagePattern":"Unable to fetch principal for user \\$user ","errorType":"console","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"apps/dav/lib/Command/ClearCalendarUnshares.php","lineNumber":65,"sourceCode":"\t#[\\Override]\n\tprotected function configure(): void {\n\t\t$this->addArgument(\n\t\t\t'uid',\n\t\t\tInputArgument::REQUIRED,\n\t\t\t'User whose unshares to clear'\n\t\t);\n\t}\n\n\t#[\\Override]\n\tprotected function execute(InputInterface $input, OutputInterface $output): int {\n\t\t$user = (string)$input->getArgument('uid');\n\t\tif (!$this->userManager->userExists($user)) {\n\t\t\tthrow new \\InvalidArgumentException(\"User $user is unknown\");\n\t\t}\n\n\t\t$principal = $this->principal->getPrincipalByPath('principals/users/' . $user);\n\t\tif ($principal === null) {\n\t\t\tthrow new \\InvalidArgumentException(\"Unable to fetch principal for user $user \");\n\t\t}\n\n\t\t$shares = $this->mapper->getSharesByPrincipals([$principal['uri']], 'calendar');\n\t\t$unshares = array_filter($shares, static fn ($share) => $share['access'] === BackendAlias::ACCESS_UNSHARED);\n\n\t\tif (count($unshares) === 0) {\n\t\t\t$output->writeln(\"User $user has no calendar unshares\");\n\t\t\treturn self::SUCCESS;\n\t\t}\n\n\t\t$rows = array_map(fn ($share) => $this->formatCalendarUnshare($share), $shares);\n\n\t\t$table = new Table($output);\n\t\t$table\n\t\t\t->setHeaders(['Share Id', 'Calendar Id', 'Calendar URI', 'Calendar Name'])\n\t\t\t->setRows($rows)\n\t\t\t->render();\n","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ClearCalendarUnshares.php#L47-L83","documentation":"InvalidArgumentException from the same command when the user exists but getPrincipalByPath('principals/users/<uid>') returns null — the CalDAV principal record is missing or inconsistent with the user backend. This signals a data inconsistency (partially deleted rows, desynchronized principals table), not an input typo.","triggerScenarios":"occ dav:clear-calendar-unshares <uid> on a user whose principal entry is absent from the principal backend — e.g. users created directly in the database, LDAP users whose principal row was removed, or a user deleted while share rows still reference their principal.","commonSituations":"Manual database edits; interrupted user deletion; LDAP reconfiguration that dropped and re-created users; restored backups where oc_principals is out of sync with the user table.","solutions":["Verify the user record with occ user:info <uid>","Inspect the principals table for the row principals/users/<uid> and restore it if missing","Re-trigger principal creation by re-saving the user (change and revert a setting) or re-provisioning via LDAP","Clean up orphaned share rows with occ dav:remove-invalid-shares if the principal cannot be restored"],"exampleFix":"# before: user exists but the principal row is gone -> 'Unable to fetch principal'\nocc dav:clear-calendar-unshares jdoe\n# after: verify and repair the principal first\nocc user:info jdoe\n# DB check: SELECT * FROM oc_principals WHERE uri = 'principals/users/jdoe';\n# restore the row (or re-provision the user), then re-run\nocc dav:clear-calendar-unshares jdoe","handlingStrategy":"validation","validationCode":"#!/bin/bash\nuid=\"$1\"\nocc user:info \"$uid\" >/dev/null 2>&1 || { echo \"unknown user: $uid\" >&2; exit 1; }\n# if the user is fine but this still fails, check principal consistency before retrying:\n# SELECT * FROM oc_principals WHERE uri = \"principals/users/$uid\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Monitor principal/user table consistency after LDAP changes and restores","Avoid creating users by direct DB inserts","Keep occ dav:remove-invalid-shares in maintenance toolbox for orphaned shares"],"tags":["occ","cli","dav","principal","data-inconsistency"],"backgroundTag":"principal-not-found","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}