Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure workspace is loaded #2470

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion apps/api/src/pkg/keys/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,26 @@ export class KeyService {
this.logger.info("data from cache or db", {
data,
});
// Quick fix
if (!data.workspace) {
this.logger.warn("workspace not found, trying again", {
workspace: data.key.workspaceId,
});
await this.cache.keyByHash.remove(keyHash);
const ws = await this.db.primary.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.id, data.key.workspaceId),
});
if (!ws) {
this.logger.error("fallback workspace not found either", {
workspaceId: data.key.workspaceId,
});
return Err(new DisabledWorkspaceError(data.key.workspaceId));
}
data.workspace = ws;
}

if ((data.forWorkspace && !data.forWorkspace.enabled) || !data.workspace?.enabled) {
return Err(new DisabledWorkspaceError(data.workspace.id));
return Err(new DisabledWorkspaceError(data.workspace?.id ?? "N/A"));
}

/**
Expand Down
Loading