Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
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
77 changes: 46 additions & 31 deletions src/dispatch/case/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models and schemas for the Dispatch case management system."""

from collections import Counter, defaultdict
from datetime import datetime
from typing import Any
Expand Down Expand Up @@ -78,6 +79,7 @@

class Case(Base, TimeStampMixin, ProjectMixin):
"""SQLAlchemy model for a Case, representing an incident or issue in the system."""

__table_args__ = (UniqueConstraint("name", "project_id"),)

id = Column(Integer, primary_key=True)
Expand Down Expand Up @@ -231,18 +233,20 @@ def total_cost_new(self):

class SignalRead(DispatchBase):
"""Pydantic model for reading signal data."""

id: PrimaryKey
name: str
owner: str
description: str | None
variant: str | None
description: str | None = None
variant: str | None = None
external_id: str
external_url: str | None
external_url: str | None = None
workflow_instances: list[WorkflowInstanceRead] | None = []


class SignalInstanceRead(DispatchBase):
"""Pydantic model for reading signal instance data."""

created_at: datetime
entities: list[EntityRead] | None = []
raw: Any
Expand All @@ -252,21 +256,24 @@ class SignalInstanceRead(DispatchBase):

class ProjectRead(DispatchBase):
"""Pydantic model for reading project data."""
id: PrimaryKey | None

id: PrimaryKey | None = None
name: NameStr
display_name: str | None
color: str | None
display_name: str | None = None
color: str | None = None
allow_self_join: bool | None = Field(True, nullable=True)


# Pydantic models...
class CaseBase(DispatchBase):
"""Base Pydantic model for case data."""

title: str
description: str | None
resolution: str | None
resolution_reason: CaseResolutionReason | None
status: CaseStatus | None
visibility: Visibility | None
description: str | None = None
resolution: str | None = None
resolution_reason: CaseResolutionReason | None = None
status: CaseStatus | None = None
visibility: Visibility | None = None

@field_validator("title")
@classmethod
Expand All @@ -287,42 +294,46 @@ def description_required(cls, v):

class CaseCreate(CaseBase):
"""Pydantic model for creating a new case."""
assignee: ParticipantUpdate | None
case_priority: CasePriorityCreate | None
case_severity: CaseSeverityCreate | None
case_type: CaseTypeCreate | None
dedicated_channel: bool | None
project: ProjectRead | None
reporter: ParticipantUpdate | None

assignee: ParticipantUpdate | None = None
case_priority: CasePriorityCreate | None = None
case_severity: CaseSeverityCreate | None = None
case_type: CaseTypeCreate | None = None
dedicated_channel: bool | None = None
project: ProjectRead | None = None
reporter: ParticipantUpdate | None = None
tags: list[TagRead] | None = []
event: bool | None = False


class CaseReadBasic(DispatchBase):
"""Pydantic model for reading basic case data."""

id: PrimaryKey
name: NameStr | None
name: NameStr | None = None


class IncidentReadBasic(DispatchBase):
"""Pydantic model for reading basic incident data."""

id: PrimaryKey
name: NameStr | None
name: NameStr | None = None


class CaseReadMinimal(CaseBase):
"""Pydantic model for reading minimal case data."""

id: PrimaryKey
name: NameStr | None
status: CaseStatus | None # Used in table and for action disabling
name: NameStr | None = None
status: CaseStatus | None = None # Used in table and for action disabling
closed_at: datetime | None = None
reported_at: datetime | None = None
dedicated_channel: bool | None # Used by CaseStatus component
dedicated_channel: bool | None = None # Used by CaseStatus component
case_type: CaseTypeRead
case_severity: CaseSeverityRead
case_priority: CasePriorityRead
project: ProjectRead
assignee: ParticipantReadMinimal | None
assignee: ParticipantReadMinimal | None = None
case_costs: list[CaseCostReadMinimal] = []


Expand All @@ -331,8 +342,9 @@ class CaseReadMinimal(CaseBase):

class CaseRead(CaseBase):
"""Pydantic model for reading detailed case data."""

id: PrimaryKey
assignee: ParticipantRead | None
assignee: ParticipantRead | None = None
case_costs: list[CaseCostRead] = []
case_priority: CasePriorityRead
case_severity: CaseSeverityRead
Expand All @@ -352,7 +364,7 @@ class CaseRead(CaseBase):
project: ProjectRead
related: list[CaseReadMinimal] | None = []
reported_at: datetime | None = None
reporter: ParticipantRead | None
reporter: ParticipantRead | None = None
signal_instances: list[SignalInstanceRead] | None = []
storage: StorageRead | None = None
tags: list[TagRead] | None = []
Expand All @@ -367,15 +379,16 @@ class CaseRead(CaseBase):

class CaseUpdate(CaseBase):
"""Pydantic model for updating case data."""
assignee: ParticipantUpdate | None

assignee: ParticipantUpdate | None = None
case_costs: list[CaseCostUpdate] = []
case_priority: CasePriorityBase | None
case_severity: CaseSeverityBase | None
case_type: CaseTypeBase | None
case_priority: CasePriorityBase | None = None
case_severity: CaseSeverityBase | None = None
case_type: CaseTypeBase | None = None
closed_at: datetime | None = None
duplicates: list[CaseReadBasic] | None = []
related: list[CaseRead] | None = []
reporter: ParticipantUpdate | None
reporter: ParticipantUpdate | None = None
escalated_at: datetime | None = None
incidents: list[IncidentReadBasic] | None = []
reported_at: datetime | None = None
Expand Down Expand Up @@ -408,9 +421,11 @@ def find_exclusive(cls, tags: list[TagRead] | None) -> list[TagRead] | None:

class CasePagination(Pagination):
"""Pydantic model for paginated minimal case results."""

items: list[CaseReadMinimal] = []


class CaseExpandedPagination(Pagination):
"""Pydantic model for paginated expanded case results."""

items: list[CaseRead] = []
23 changes: 16 additions & 7 deletions src/dispatch/case/priority/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models and schemas for the Dispatch case priority system."""

from sqlalchemy import Column, Integer, String, Boolean
from sqlalchemy.sql.schema import UniqueConstraint
from sqlalchemy.event import listen
Expand All @@ -11,6 +12,7 @@

class CasePriority(Base, ProjectMixin):
"""SQLAlchemy model for a case priority, representing the priority level of a case."""

__table_args__ = (UniqueConstraint("name", "project_id"),)
id = Column(Integer, primary_key=True)
name = Column(String)
Expand All @@ -27,39 +29,46 @@ class CasePriority(Base, ProjectMixin):
search_vector = Column(TSVectorType("name", "description"))


default_listener_doc = """Ensure only one default priority per project by listening to the 'default' field."""
default_listener_doc = (
"""Ensure only one default priority per project by listening to the 'default' field."""
)

listen(CasePriority.default, "set", ensure_unique_default_per_project)


# Pydantic models
class CasePriorityBase(DispatchBase):
"""Base Pydantic model for case priority data."""

color: str | None = None
default: bool | None
page_assignee: bool | None
default: bool | None = None
page_assignee: bool | None = None
description: str | None = None
enabled: bool | None
enabled: bool | None = None
name: NameStr
project: ProjectRead | None
view_order: int | None
project: ProjectRead | None = None
view_order: int | None = None


class CasePriorityCreate(CasePriorityBase):
"""Pydantic model for creating a new case priority."""

pass


class CasePriorityUpdate(CasePriorityBase):
"""Pydantic model for updating a case priority."""

pass


class CasePriorityRead(CasePriorityBase):
"""Pydantic model for reading case priority data."""
id: PrimaryKey | None

id: PrimaryKey | None = None


class CasePriorityPagination(Pagination):
"""Pydantic model for paginated case priority results."""

items: list[CasePriorityRead] = []
14 changes: 10 additions & 4 deletions src/dispatch/case/severity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

class CaseSeverity(Base, ProjectMixin):
"""SQLAlchemy model for a case severity, representing the severity level of a case."""

__table_args__ = (UniqueConstraint("name", "project_id"),)
id = Column(Integer, primary_key=True)
name = Column(String)
Expand Down Expand Up @@ -39,30 +40,35 @@ class CaseSeverity(Base, ProjectMixin):
# Pydantic models
class CaseSeverityBase(DispatchBase):
"""Base Pydantic model for case severity data."""

color: str | None = None
default: bool | None
default: bool | None = None
description: str | None = None
enabled: bool | None
enabled: bool | None = None
name: NameStr
project: ProjectRead | None
view_order: int | None
project: ProjectRead | None = None
view_order: int | None = None


class CaseSeverityCreate(CaseSeverityBase):
"""Pydantic model for creating a new case severity."""

pass


class CaseSeverityUpdate(CaseSeverityBase):
"""Pydantic model for updating a case severity."""

pass


class CaseSeverityRead(CaseSeverityBase):
"""Pydantic model for reading case severity data."""

id: PrimaryKey


class CaseSeverityPagination(Pagination):
"""Pydantic model for paginated case severity results."""

items: list[CaseSeverityRead] = []
4 changes: 2 additions & 2 deletions src/dispatch/case_cost_type/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class CaseCostTypeBase(DispatchBase):
description: str | None = None
category: str | None = None
details: dict | None = {}
created_at: datetime | None
editable: bool | None
created_at: datetime | None = None
editable: bool | None = None
model_type: str | None = Field(None, nullable=False)


Expand Down
3 changes: 2 additions & 1 deletion src/dispatch/cost_model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class CostModel(Base, TimeStampMixin, ProjectMixin):
# Pydantic Models
class CostModelActivityBase(DispatchBase):
"""Base class for cost model activity resources"""

plugin_event: PluginEventRead
response_time_seconds: int | None = 300
enabled: bool | None = Field(True, nullable=True)
Expand All @@ -81,7 +82,7 @@ class CostModelActivityRead(CostModelActivityBase):


class CostModelActivityUpdate(CostModelActivityBase):
id: PrimaryKey | None
id: PrimaryKey | None = None


class CostModelBase(DispatchBase):
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/data/alert/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AlertCreate(AlertBase):


class AlertUpdate(AlertBase):
id: PrimaryKey | None
id: PrimaryKey | None = None


class AlertRead(AlertBase):
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/data/query/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class QueryCreate(QueryBase):


class QueryUpdate(QueryBase):
id: PrimaryKey | None
id: PrimaryKey | None = None


class QueryRead(QueryBase):
Expand Down
14 changes: 7 additions & 7 deletions src/dispatch/data/source/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ class SourceBase(DispatchBase):
incidents: list[IncidentRead | None] = []
queries: list[QueryReadMinimal | None] = []
alerts: list[AlertRead | None] = []
cost: float | None
cost: float | None = None
owner: ServiceRead | None = None
source_type: SourceTypeRead | None
source_environment: SourceEnvironmentRead | None
source_data_format: SourceDataFormatRead | None
source_status: SourceStatusRead | None
source_transport: SourceTransportRead | None
source_type: SourceTypeRead | None = None
source_environment: SourceEnvironmentRead | None = None
source_data_format: SourceDataFormatRead | None = None
source_status: SourceStatusRead | None = None
source_transport: SourceTransportRead | None = None
project: ProjectRead


Expand All @@ -148,7 +148,7 @@ class SourceCreate(SourceBase):


class SourceUpdate(SourceBase):
id: PrimaryKey | None
id: PrimaryKey | None = None


class SourceRead(SourceBase):
Expand Down
4 changes: 2 additions & 2 deletions src/dispatch/definition/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class Definition(Base, ProjectMixin):


class DefinitionTerm(DispatchBase):
id: PrimaryKey | None
text: str | None
id: PrimaryKey | None = None
text: str | None = None


# Pydantic models...
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/document/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DocumentCreate(DocumentBase):
class DocumentUpdate(DocumentBase):
"""Pydantic model for updating a document resource."""

filters: list[SearchFilterRead] | None
filters: list[SearchFilterRead] | None = None
tags: list[TagRead] | None = []

@field_validator("tags")
Expand Down
Loading
Loading