Skip to content
Merged
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
23 changes: 19 additions & 4 deletions database_api/model_planitem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import enum
import uuid
from datetime import datetime, UTC
from typing import TYPE_CHECKING
from database_api.planexe_db_singleton import db
from sqlalchemy_utils import UUIDType
from sqlalchemy import JSON
Expand Down Expand Up @@ -104,10 +105,13 @@ class PlanItem(db.Model):
# Artifact schema/version marker (legacy snapshots are NULL/1, split-storage snapshots are 2+).
run_artifact_layout_version = db.Column(db.Integer, nullable=True, default=None)

# Lightweight admin/UI helpers; avoids loading large payload columns just to render links.
has_generated_report_html = column_property(generated_report_html.isnot(None))
has_run_zip_snapshot = column_property(run_zip_snapshot.isnot(None))
has_run_track_activity_jsonl = column_property(run_track_activity_jsonl.isnot(None))
# Lightweight IS NOT NULL checks (actual column_property assigned after class body).
# TYPE_CHECKING-only annotations so pyright knows the types without confusing
# SQLAlchemy's declarative metaclass at runtime.
if TYPE_CHECKING:
has_generated_report_html: bool
has_run_zip_snapshot: bool
has_run_track_activity_jsonl: bool

def __repr__(self):
return f"{self.id}: {self.timestamp_created}, {self.state}, {self.prompt!r}, parameters: {self.parameters!r}"
Expand Down Expand Up @@ -148,6 +152,17 @@ def demo_items(cls) -> list['PlanItem']:
return [task1, task2, task3]


# Lightweight IS NOT NULL checks — defined outside the class body because
# deferred() descriptors do not support .isnot() at class-definition time
# (produces NotImplemented). Using __table__.c gives us the raw Column
# objects which support SQL operators correctly.
_t = PlanItem.__table__.c
PlanItem.has_generated_report_html = column_property(_t.generated_report_html.isnot(None))
PlanItem.has_run_zip_snapshot = column_property(_t.run_zip_snapshot.isnot(None))
PlanItem.has_run_track_activity_jsonl = column_property(_t.run_track_activity_jsonl.isnot(None))
del _t


@event.listens_for(PlanItem, "before_insert")
@event.listens_for(PlanItem, "before_update")
def _sanitize_planitem_fields(_mapper, _connection, target):
Expand Down