{"record":{"id":"f4fbaa259c78da24","repo":"n8n-io/n8n","slug":"404-f4fbaa","errorCode":"404","errorMessage":"Could not find owner for credential \"${existingCredential.id}\"","messagePattern":"Could not find owner for credential \"(.+?)\"","errorType":"exception","errorClass":"NotFoundError","httpStatus":404,"severity":"critical","filePath":"packages/cli/src/credentials/credentials.service.ts","lineNumber":787,"sourceCode":"\t\t\tmergedData.data = this.unredact(\n\t\t\t\tmergedData.data,\n\t\t\t\tdecryptedData,\n\t\t\t\tthis.getCredentialTypeProperties(existingCredential.type),\n\t\t\t);\n\t\t}\n\t\tif (existingCredential.usageScope === 'instance') {\n\t\t\tawait this.validateInstanceCredentialUpdate(\n\t\t\t\texistingCredential,\n\t\t\t\tmergedData.data ?? decryptedData,\n\t\t\t\tundefined,\n\t\t\t\toptions?.operationContext,\n\t\t\t);\n\t\t} else {\n\t\t\tconst projectOwningCredential = existingCredential.shared?.find(\n\t\t\t\t(shared) => shared.role === 'credential:owner',\n\t\t\t);\n\t\t\tif (!projectOwningCredential) {\n\t\t\t\tthrow new NotFoundError(`Could not find owner for credential \"${existingCredential.id}\"`);\n\t\t\t}\n\n\t\t\tawait validateExternalSecretsPermissions({\n\t\t\t\tuser,\n\t\t\t\tprojectId: projectOwningCredential.projectId,\n\t\t\t\tdataToSave: data.data,\n\t\t\t\tdecryptedExistingData: decryptedData,\n\t\t\t});\n\n\t\t\tif (this.externalSecretsConfig.externalSecretsForProjects && data.data) {\n\t\t\t\tawait validateAccessToReferencedSecretProviders(\n\t\t\t\t\tprojectOwningCredential.projectId,\n\t\t\t\t\tdata.data,\n\t\t\t\t\tthis.externalSecretsProviderAccessCheckService,\n\t\t\t\t\t'update',\n\t\t\t\t);\n\t\t\t}\n\t\t}","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/credentials/credentials.service.ts#L769-L805","documentation":"Thrown by CredentialsService.prepareUpdateData when an existing project-scoped credential has no shared row with role 'credential:owner'. Every project credential must have exactly one owner sharing; the absence indicates data corruption (orphaned credential row) — an integrity error, not a normal user mistake.","triggerScenarios":"PATCH /credentials/:id on a project credential whose shared_credentials owner row was deleted or never created (manual DB edit, failed migration, partial cleanup).","commonSituations":"Direct database manipulation removed the owner sharing. A buggy migration left orphaned credentials. Re-assigning ownership failed midway.","solutions":["Restore the missing owner sharing row in shared_credentials (projectId of the true owner, role 'credential:owner') via admin/DB tooling.","Re-run the ownership repair migration or use the admin API to reassign ownership.","If irreparable, delete the orphaned credential and recreate it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// This is a data-integrity error; pre-check the owner sharing exists.\nconst owner = credential.shared?.find(s => s.role === 'credential:owner');\nif (!owner) {\n  throw new Error('Orphaned credential — repair the owner sharing before update.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await service.prepareUpdateData(user, data, existing);\n} catch (e) {\n  if (/Could not find owner for credential/i.test(e.message)) {\n    // page admins: run ownership repair / reassign owner manually\n  } else throw e;\n}","preventionTips":["Never delete shared_credentials owner rows directly in the DB.","Run ownership-repair migrations after bulk data operations.","Monitor for orphaned credentials (credential rows with no owner sharing)."],"tags":["credentials","data-integrity","ownership","database"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}