Skip to content

Commit

Permalink
fix: optional workspace
Browse files Browse the repository at this point in the history
fixes optional workspace function to not raise an error if workspace isn't found
  • Loading branch information
Erez Sharim committed Jul 3, 2024
1 parent 4a94c81 commit bec8575
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions app/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from abc import ABC, abstractmethod
from typing import Annotated, Any, List, Optional
from typing import Annotated, Any, Optional

import jwt
import requests
Expand Down Expand Up @@ -153,18 +153,13 @@ async def get_current_workspace(
async def get_optional_current_workspace(
current_user: Annotated[CurrentUser, Depends(get_current_active_user)],
workspace_store: WorkspaceStore = Depends(get_service(WorkspaceStore)),
):
) -> Optional[Workspace]:
workspace_id = current_user.workspace_id
if workspace_id is None:
return None

with SQLAlchemyTransactionContext().manage() as tx_context:
ws = workspace_store.get_by_id(workspace_id, tx_context=tx_context)
if ws is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="workspace not found"
)

return ws


Expand Down

0 comments on commit bec8575

Please sign in to comment.