Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions api/app/agents/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,8 @@ async def process_turn(
ConversationRuntimeState.conversation_id == conversation.id
)
)
runtime_state = state_result.scalar_one_or_none()
conv_state = ""
if runtime_state:
if runtime_state := state_result.scalar_one_or_none():
try:
state_data = json.loads(runtime_state.state_json)
conv_state = state_data.get("conversationState", "")
Expand Down
9 changes: 3 additions & 6 deletions api/app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,7 @@ async def send_message(
ConversationTurn.client_msg_id == body.client_msg_id,
)
)
turn = existing.scalars().first()
if turn is None:
if (turn := existing.scalars().first()) is None:
raise HTTPException(status_code=500, detail="Turn conflict")
if turn.status == "completed" and turn.assistant_message_id is not None:
asst_result = await db.execute(
Expand All @@ -1068,8 +1067,7 @@ async def send_message(
ConversationTurn.id == turn_id,
)
)
turn = re_result.scalars().first()
if turn is None:
if (turn := re_result.scalars().first()) is None:
break
if (
turn.status == "completed"
Expand Down Expand Up @@ -1595,8 +1593,7 @@ async def admin_update_project(
db: AsyncSession = Depends(get_db),
) -> dict[str, str]:
result = await db.execute(select(Project).where(Project.id == project_id))
project = result.scalar_one_or_none()
if project is None:
if (project := result.scalar_one_or_none()) is None:
raise HTTPException(status_code=404, detail="Project not found")
if body.display_name is not None:
project.display_name = body.display_name.strip()
Expand Down
9 changes: 3 additions & 6 deletions api/app/services/outbox_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ def _parse_preferred_time(preferred_time: str) -> tuple[int, int]:
value = preferred_time.strip().lower()
if not value:
return 9, 0
match_24h = re.fullmatch(r"([01]?\d|2[0-3]):([0-5]\d)", value)
if match_24h:
if match_24h := re.fullmatch(r"([01]?\d|2[0-3]):([0-5]\d)", value):
return int(match_24h.group(1)), int(match_24h.group(2))
match_ampm = re.fullmatch(r"(\d{1,2})(?::([0-5]\d))?\s*(am|pm)", value)
if match_ampm:
if match_ampm := re.fullmatch(r"(\d{1,2})(?::([0-5]\d))?\s*(am|pm)", value):
hour = int(match_ampm.group(1)) % 12
if match_ampm.group(3) == "pm":
hour += 12
Expand Down Expand Up @@ -50,8 +48,7 @@ async def enqueue_outbox_event(
existing_result = await db.execute(
select(OutboxEvent).where(OutboxEvent.dedupe_key == dedupe_key)
)
existing = existing_result.scalar_one_or_none()
if existing is not None:
if (existing := existing_result.scalar_one_or_none()) is not None:
return existing
event = OutboxEvent(
project_id=project_id,
Expand Down
11 changes: 5 additions & 6 deletions api/app/services/profile_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ async def load_user_profile(db: AsyncSession, membership_id: int) -> UserProfile
mem_res = await db.execute(
select(ProjectMembership.user_id).where(ProjectMembership.id == membership_id)
)
user_id = mem_res.scalar_one_or_none()

if user_id:
if user_id := mem_res.scalar_one_or_none():
user_res = await db.execute(
select(FlowUserProfile).where(FlowUserProfile.user_id == user_id)
)
user_profile = user_res.scalar_one_or_none()
if user_profile and user_profile.display_name:
if (
user_profile := user_res.scalar_one_or_none()
) and user_profile.display_name:
profile.display_name = user_profile.display_name

return profile
Expand All @@ -86,10 +86,9 @@ async def save_user_profile(
result = await db.execute(
select(UserProfileStore).where(UserProfileStore.membership_id == membership_id)
)
row = result.scalar_one_or_none()
# Exclude display_name from persistence in JSON store as it's transient/derived
profile_json = profile.model_dump_json(exclude={"display_name"})
if row is None:
if (row := result.scalar_one_or_none()) is None:
row = UserProfileStore(
membership_id=membership_id,
profile_json=profile_json,
Expand Down