alibaba/spring-ai-alibaba · error · BizException
DefaultWorkspaceNotFound
DefaultWorkspaceNotFound
Error message
Default workspace can not be found.
What it means
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.
Source
Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/service/impl/AccountServiceImpl.java:113
*/
@Override
public TokenResponse login(LoginRequest loginRequest) {
AccountEntity accountEntity = getAccountByName(loginRequest.getUsername());
if (accountEntity == null) {
throw new BizException(ErrorCode.ACCOUNT_LOGIN_ERROR.toError());
}
if (!PasswordCryptUtils.match(loginRequest.getPassword(), accountEntity.getPassword())) {
throw new BizException(ErrorCode.ACCOUNT_LOGIN_ERROR.toError());
}
accountEntity.setGmtLastLogin(new Date());
this.updateById(accountEntity);
// cache it
Workspace workspace = workspaceService.getDefaultWorkspace(accountEntity.getAccountId());
if (workspace == null) {
throw new BizException(ErrorCode.DEFAULT_WORKSPACE_NOT_FOUND.toError());
}
accountEntity.setDefaultWorkspaceId(workspace.getWorkspaceId());
String key = getAccountCacheKey(accountEntity.getAccountId());
redisManager.put(key, accountEntity);
String accountId = accountEntity.getAccountId();
return createTokenResponse(accountId);
}
/**
* Refreshes access token using refresh token
* @param refreshTokenRequest Refresh token request
* @return New token response
*/
@Override
public TokenResponse refreshToken(RefreshTokenRequest refreshTokenRequest) {
String accountId = tokenManager.getAccountIdFromRefreshToken(refreshTokenRequest.getRefreshToken());View on GitHub (pinned to f82da0b50f)
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.
Example fix
// Direct DB seed without workspace (before)
INSERT INTO account (account_id, username, password) VALUES ('acc1','dev','{bcrypt}...');
// after: create the workspace too
INSERT INTO account (account_id, username, password) VALUES ('acc1','dev','{bcrypt}...');
INSERT INTO workspace (workspace_id, account_id, name) VALUES ('ws1','acc1','default'); Defensive patterns
Strategy: try-catch
Validate before calling
// caller-side pre-check
boolean hasWorkspace = workspaceService.getDefaultWorkspace(accountId) != null;
if (!hasWorkspace) { /* repair or re-register account before login */ } Try / catch
try {
TokenResponse resp = accountService.login(loginRequest);
} catch (BizException e) {
if ("DefaultWorkspaceNotFound".equals(e.getCode())) {
// repair account: recreate default workspace or re-register, then retry login
} else { throw e; }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/2678bed75fd95824.
Report an issue: GitHub.