{"record":{"id":"1f80f245c27ffed0","repo":"alibaba/spring-ai-alibaba","slug":"accountnotfound","errorCode":"AccountNotFound","errorMessage":"Account can not be found.","messagePattern":"Account can not be found\\.","errorType":"error_code","errorClass":"BizException","httpStatus":404,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AccountServiceImpl.java","lineNumber":165,"sourceCode":"\t\tString accountId;\n\t\tAccountEntity accountEntity = getAccountByName(oauth2User.getUserId());\n\t\tif (accountEntity == null) {\n\t\t\tAccount account = new Account();\n\t\t\taccount.setUsername(oauth2User.getUserId());\n\t\t\taccount.setNickname(oauth2User.getName());\n\t\t\taccount.setEmail(oauth2User.getEmail());\n\t\t\taccount.setIcon(oauth2User.getIcon());\n\t\t\taccount.setPassword(IdGenerator.uuid32());\n\n\t\t\taccountId = registerAccount(account);\n\t\t\taccountEntity = getAccountById(accountId);\n\t\t}\n\t\telse {\n\t\t\taccountId = accountEntity.getAccountId();\n\t\t}\n\n\t\tif (accountEntity == null) {\n\t\t\tthrow new BizException(ErrorCode.ACCOUNT_NOT_FOUND.toError());\n\t\t}\n\n\t\t// cache it\n\t\tWorkspace workspace = workspaceService.getDefaultWorkspace(accountEntity.getAccountId());\n\t\tif (workspace == null) {\n\t\t\tthrow new BizException(ErrorCode.DEFAULT_WORKSPACE_NOT_FOUND.toError());\n\t\t}\n\n\t\taccountEntity.setDefaultWorkspaceId(workspace.getWorkspaceId());\n\t\tString key = getAccountCacheKey(accountEntity.getAccountId());\n\t\tredisManager.put(key, accountEntity);\n\n\t\treturn createTokenResponse(accountId);\n\t}\n\n\t/**\n\t * Invalidates access token on logout\n\t * @param accessToken Token to invalidate","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AccountServiceImpl.java#L147-L183","documentation":"Thrown by AccountServiceImpl.login(Oauth2User) when, after either looking up an existing account or registering a new one and fetching it back via getAccountById, the account entity is still null. Practically this means the auto-registration path registered an account but the subsequent read failed, an unlikely internal-inconsistency condition in the OAuth2 login flow.","triggerScenarios":"OAuth2 login with a new userId where registerAccount succeeds but getAccountById(accountId) returns null — e.g. the insert was rolled back, replication lag on a read replica, or the read races with a concurrent delete of the same username.","commonSituations":"Database read-replica lag immediately after registration; a concurrent request deleting the just-created account; DB transaction/save failure swallowed upstream so the id exists but the row does not; corrupted cache returning a stale/missing mapping.","solutions":["Retry the OAuth2 login; transient read lag usually resolves on a second attempt.","Check the account table for the row that registerAccount should have inserted and inspect app logs for save() failures.","If using a read replica, ensure the post-registration read hits the primary or waits for replication.","Clear/purge any stale Redis cache entries under the account cache key prefix and retry."],"exampleFix":"// before: read immediately after register (replica may lag)\nString accountId = registerAccount(account);\nAccountEntity entity = getAccountById(accountId); // null -> BizException\n\n// after: fail fast with a clear cause if the row is missing\nString accountId = registerAccount(account);\nAccountEntity entity = getAccountById(accountId);\nif (entity == null) {\n    throw new IllegalStateException(\"Account row missing after registration: \" + accountId);\n}","handlingStrategy":"retry","validationCode":"// verify account row exists after registration before login proceeds\nAccountEntity check = accountService.getAccountById(accountId);\nif (check == null) { /* surface a clear registration-consistency error */ }","typeGuard":null,"tryCatchPattern":"try {\n    return accountService.login(oauth2User);\n} catch (BizException e) {\n    if (\"AccountNotFound\".equals(e.getCode())) {\n        // one short retry for replica lag, then surface a 500 with the accountId\n        return retryLoginOnce(oauth2User);\n    }\n    throw e;\n}","preventionTips":["Read the freshly registered account from the primary DB, not a lagging replica.","Ensure registerAccount failures propagate instead of being swallowed.","Avoid flows that can delete an account concurrently with its first OAuth2 login.","Log the accountId with the error to speed up diagnosing DB consistency issues."],"tags":["auth","oauth2","database","internal-invariant","spring-ai-alibaba-admin"],"backgroundTag":"entity-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}