{"record":{"id":"2678bed75fd95824","repo":"alibaba/spring-ai-alibaba","slug":"defaultworkspacenotfound","errorCode":"DefaultWorkspaceNotFound","errorMessage":"Default workspace can not be found.","messagePattern":"Default workspace 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":113,"sourceCode":"\t */\n\t@Override\n\tpublic TokenResponse login(LoginRequest loginRequest) {\n\t\tAccountEntity accountEntity = getAccountByName(loginRequest.getUsername());\n\t\tif (accountEntity == null) {\n\t\t\tthrow new BizException(ErrorCode.ACCOUNT_LOGIN_ERROR.toError());\n\t\t}\n\n\t\tif (!PasswordCryptUtils.match(loginRequest.getPassword(), accountEntity.getPassword())) {\n\t\t\tthrow new BizException(ErrorCode.ACCOUNT_LOGIN_ERROR.toError());\n\t\t}\n\n\t\taccountEntity.setGmtLastLogin(new Date());\n\t\tthis.updateById(accountEntity);\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\tString accountId = accountEntity.getAccountId();\n\t\treturn createTokenResponse(accountId);\n\t}\n\n\t/**\n\t * Refreshes access token using refresh token\n\t * @param refreshTokenRequest Refresh token request\n\t * @return New token response\n\t */\n\t@Override\n\tpublic TokenResponse refreshToken(RefreshTokenRequest refreshTokenRequest) {\n\t\tString accountId = tokenManager.getAccountIdFromRefreshToken(refreshTokenRequest.getRefreshToken());","sourceCodeStart":95,"sourceCodeEnd":131,"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#L95-L131","documentation":"Thrown by AccountServiceImpl.login(LoginRequest) after username/password verification succeeds, when workspaceService.getDefaultWorkspace(accountId) returns null. Spring AI Alibaba Admin expects every account to own a default workspace, and the login flow cannot cache the account or mint tokens without a workspace id. It indicates the account exists and credentials are valid, but the workspace row backing it is missing from the database.","triggerScenarios":"Calling the admin login endpoint with valid credentials for an account whose default workspace record was deleted, was never created (e.g. account created outside registerAccount or by direct DB insert/import), or whose workspace_id column is null/stale.","commonSituations":"Manually seeded database rows without the corresponding workspace entry; a migration or cleanup script deleted workspace rows; Redis/DB drift after restoring a partial backup; failure in registerAccount's createWorkspace step in an earlier version leaving accounts orphaned.","solutions":["Query the workspace table for the account's default workspace and recreate it if missing (the app's createWorkspace path shows the required fields).","Fix the account row's default_workspace_id to point at an existing workspace belonging to the account.","If the account is a test artifact, delete and re-register the account via the normal registration flow so the workspace is created automatically.","Check for recent workspace-table migrations/cleanups and restore the deleted rows from backup."],"exampleFix":"// Direct DB seed without workspace (before)\nINSERT INTO account (account_id, username, password) VALUES ('acc1','dev','{bcrypt}...');\n\n// after: create the workspace too\nINSERT INTO account (account_id, username, password) VALUES ('acc1','dev','{bcrypt}...');\nINSERT INTO workspace (workspace_id, account_id, name) VALUES ('ws1','acc1','default');","handlingStrategy":"try-catch","validationCode":"// caller-side pre-check\nboolean hasWorkspace = workspaceService.getDefaultWorkspace(accountId) != null;\nif (!hasWorkspace) { /* repair or re-register account before login */ }","typeGuard":null,"tryCatchPattern":"try {\n    TokenResponse resp = accountService.login(loginRequest);\n} catch (BizException e) {\n    if (\"DefaultWorkspaceNotFound\".equals(e.getCode())) {\n        // repair account: recreate default workspace or re-register, then retry login\n    } else { throw e; }\n}","preventionTips":["Always create accounts through registerAccount, which provisions the workspace automatically.","Never delete workspace rows without reassigning or deleting dependent accounts.","Add a scheduled consistency check joining account.default_workspace_id against the workspace table."],"tags":["login","workspace","database","spring-ai-alibaba-admin"],"backgroundTag":"resource-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"}