Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit f854816

Browse files
Raise WorkspaceDoesNotExistError on update system-prompt
1 parent d05df39 commit f854816

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/codegate/db/connection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def record_context(self, context: Optional[PipelineContext]) -> None:
248248
except Exception as e:
249249
logger.error(f"Failed to record context: {context}.", error=str(e))
250250

251-
async def add_workspace(self, workspace_name: str) -> Optional[Workspace]:
251+
async def add_workspace(self, workspace_name: str) -> Workspace:
252252
"""Add a new workspace to the DB.
253253
254254
This handles validation and insertion of a new workspace.
@@ -274,7 +274,7 @@ async def add_workspace(self, workspace_name: str) -> Optional[Workspace]:
274274
raise AlreadyExistsError(f"Workspace {workspace_name} already exists.")
275275
return added_workspace
276276

277-
async def update_workspace(self, workspace: Workspace) -> Optional[Workspace]:
277+
async def update_workspace(self, workspace: Workspace) -> Workspace:
278278
sql = text(
279279
"""
280280
UPDATE workspaces SET
@@ -284,8 +284,7 @@ async def update_workspace(self, workspace: Workspace) -> Optional[Workspace]:
284284
RETURNING *
285285
"""
286286
)
287-
# We only pass an object to respect the signature of the function
288-
updated_workspace = await self._execute_update_pydantic_model(workspace, sql)
287+
updated_workspace = await self._execute_update_pydantic_model(workspace, sql, should_raise=True)
289288
return updated_workspace
290289

291290
async def update_session(self, session: Session) -> Optional[Session]:

src/codegate/pipeline/cli/commands.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,15 @@ async def _set_system_prompt(self, flags: Dict[str, str], args: List[str]) -> st
244244
active_workspace = await self.workspace_crud.get_active_workspace()
245245
workspace_name = active_workspace.name
246246

247-
updated_worksapce = await self.workspace_crud.update_workspace_system_prompt(
248-
workspace_name, args
249-
)
250-
if not updated_worksapce:
247+
try:
248+
updated_worksapce = await self.workspace_crud.update_workspace_system_prompt(
249+
workspace_name, args
250+
)
251+
except crud.WorkspaceDoesNotExistError:
251252
return (
252-
f"Workspace system prompt not updated. "
253-
f"Check if the workspace `{workspace_name}` exists"
253+
f"Workspace system prompt not updated. Workspace `{workspace_name}` doesn't exist"
254254
)
255+
255256
return (
256257
f"Workspace `{updated_worksapce.name}` system prompt "
257258
f"updated to:\n```\n{updated_worksapce.system_prompt}\n```"

src/codegate/workspaces/crud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ async def activate_workspace(self, workspace_name: str):
8585

8686
async def update_workspace_system_prompt(
8787
self, workspace_name: str, sys_prompt_lst: List[str]
88-
) -> Optional[Workspace]:
88+
) -> Workspace:
8989
selected_workspace = await self._db_reader.get_workspace_by_name(workspace_name)
9090
if not selected_workspace:
91-
return None
91+
raise WorkspaceDoesNotExistError(f"Workspace {workspace_name} does not exist.")
9292

9393
system_prompt = " ".join(sys_prompt_lst)
9494
workspace_update = Workspace(

0 commit comments

Comments
 (0)