Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
6 changes: 6 additions & 0 deletions packages/tracecat-registry/tracecat_registry/core/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from tracecat.cases.service import CasesService, CaseCommentsService
from tracecat.db.engine import get_async_session_context_manager
from tracecat.auth.users import lookup_user_by_email
from tracecat.cases.tags.schemas import CaseTagRead
from tracecat.tags.schemas import TagRead, TagCreate
from tracecat.tables.common import coerce_optional_to_utc_datetime
from tracecat_registry import registry
Expand Down Expand Up @@ -363,6 +364,10 @@ async def get_case(
)
)

# Get tags for the case
tags = await service.tags.list_tags_for_case(case.id)
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P0: Using service outside its async with context manager will cause a runtime error. The database session is closed after the async with CasesService.with_session() as service: block ends. Move this code inside the context manager block.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/tracecat-registry/tracecat_registry/core/cases.py, line 368:

<comment>Using `service` outside its `async with` context manager will cause a runtime error. The database session is closed after the `async with CasesService.with_session() as service:` block ends. Move this code inside the context manager block.</comment>

<file context>
@@ -363,6 +364,10 @@ async def get_case(
         )
 
+    # Get tags for the case
+    tags = await service.tags.list_tags_for_case(case.id)
+    tag_reads = [CaseTagRead.model_validate(tag, from_attributes=True) for tag in tags]
+
</file context>
Fix with Cubic

tag_reads = [CaseTagRead.model_validate(tag, from_attributes=True) for tag in tags]
Comment on lines +367 to +369

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fetching case tags after DB session is closed

After CasesService.with_session() exits, the DB session is closed, but service.tags.list_tags_for_case(case.id) is called afterward to build the response. This call will execute with a closed session and raise when the get_case registry action is invoked, so the new tags payload cannot be returned at all. Move the tag lookup inside the async with block or keep the session open while querying tags.

Useful? React with 👍 / 👎.


# Convert any UUID to string before serializing
case_read = CaseRead(
id=case.id, # Use UUID directly
Expand All @@ -376,6 +381,7 @@ async def get_case(
description=case.description,
fields=final_fields,
payload=case.payload,
tags=tag_reads,
)

# Use model_dump(mode="json") to ensure UUIDs are converted to strings
Expand Down
4 changes: 4 additions & 0 deletions tracecat/cases/durations/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class CaseDurationMetric(BaseModel):
case_priority: str = Field(..., description="Case priority value")
case_severity: str = Field(..., description="Case severity value")
case_status: str = Field(..., description="Case status value")
case_tags: list[str] = Field(
default_factory=list,
description="List of tag refs associated with the case",
)

# Case identifiers (high cardinality - for drill-down/lookups)
case_id: str = Field(..., description="Case UUID for lookups")
Expand Down
1 change: 1 addition & 0 deletions tracecat/cases/durations/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def _format_time_series(
case_priority=case.priority.value,
case_severity=case.severity.value,
case_status=case.status.value,
case_tags=[tag.ref for tag in case.tags],
# Case identifiers (high cardinality, for drill-down)
case_id=str(case.id),
case_short_id=case.short_id,
Expand Down