{"record":{"id":"f627bfd83fbc8971","repo":"nextcloud/server","slug":"unable-to-fetch-principal-for-user-user-f627bf","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/ListCalendarShares.php","lineNumber":65,"sourceCode":"\t\t$this->addOption(\n\t\t\t'calendar-id',\n\t\t\t'',\n\t\t\tInputOption::VALUE_REQUIRED,\n\t\t\t'List only shares for the given calendar id id',\n\t\t\tnull,\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$memberships = array_merge(\n\t\t\t[$principal['uri']],\n\t\t\t$this->principal->getGroupMembership($principal['uri']),\n\t\t\t$this->principal->getCircleMembership($principal['uri']),\n\t\t);\n\n\t\t$shares = $this->mapper->getSharesByPrincipals($memberships, 'calendar');\n\n\t\t$calendarId = $input->getOption('calendar-id');\n\t\tif ($calendarId !== null) {\n\t\t\t$shares = array_filter($shares, fn ($share) => $share['resourceid'] === (int)$calendarId);\n\t\t}\n\n\t\t$rows = array_map(fn ($share) => $this->formatCalendarShare($share), $shares);\n\n\t\tif (count($rows) > 0) {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/nextcloud/server/blob/ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3/apps/dav/lib/Command/ListCalendarShares.php#L47-L83","documentation":"Thrown by occ dav:list-calendar-shares when the user exists in the user backend but IPrincipalBackend::getPrincipalByPath('principals/users/<uid>') returns null. Unlike errors 302, this indicates a data inconsistency: the account row exists while the DAV principal row for it does not. The command aborts before collecting group/circle memberships or shares.","triggerScenarios":"User record present but the DAV principals entry missing or mis-persisted (partially failed provisioning, interrupted dav migration, manually edited database, inconsistent restore); LDAP user known to the user backend but principal not created on first DAV touch.","commonSituations":"Database restored without the principals tables; an occ upgrade with pending dav app migrations was interrupted; user inserted directly via SQL; instance cloned between environments with diverging dav schema state.","solutions":["Run `occ upgrade` to apply any pending migrations for dav","Inspect the principal row: `SELECT * FROM oc_principals WHERE uri = 'principals/users/<uid>'`","If using LDAP, re-sync users and have the user log in once so the principal is provisioned","As a last resort on a dev instance, recreate the user after exporting their data"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"php occ user:info \"$uid\" >/dev/null 2>&1 || exit 1\n# principal sanity check before the shares command\nphp -r '\n  $p = OC::$server->get(\\OCA\\DAV\\DAV\\PrincipalBackend::class)->getPrincipalByPath(\"principals/users/$argv[1]\");\n  exit($p === null ? 1 : 0);\n' \"$uid\" || { echo \"Principal missing for $uid — run occ upgrade\" >&2; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `occ upgrade` after restoring or cloning databases so dav migrations complete","Never insert users directly via SQL; use provisioning APIs so principals are created","Monitor for userExists-vs-principal drift after interrupted migrations"],"tags":["dav","principal","calendar","shares","occ","data-consistency"],"backgroundTag":"principal-not-found","analyzedSha":"ecdeb153ffdf227235c9a7e2d13dbe0f9c817bc3","analyzedAt":"2026-08-17T01:36:13.386Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}