Skip to content

Commit 7789cdb

Browse files
committed
Relationships declare their loading: eager where read, loud where unused
1 parent 8932006 commit 7789cdb

4 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎backend/druks/contrib/ship/models.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ProjectRepo(StoredSubject):
7676
profile: Mapped[dict[str, Any]] = mapped_column(JSONB, default=dict)
7777
created_at: Mapped[datetime] = mapped_column(default=Base.utc_now)
7878

79-
project: Mapped[Project] = relationship(back_populates="repos")
79+
project: Mapped[Project] = relationship(back_populates="repos", lazy="joined")
8080

8181
@classmethod
8282
def create(

‎backend/druks/durable/models.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ class AgentCall(Base, Uuid7Pk):
419419
model: Mapped[str] = mapped_column(String)
420420
# The run this LLM call ran in. ON DELETE CASCADE, so a call never outlives it.
421421
run_id: Mapped[str] = mapped_column(ForeignKey("durable_runs.id", ondelete="CASCADE"))
422-
run: Mapped["Run"] = relationship(back_populates="agent_calls")
422+
run: Mapped["Run"] = relationship(back_populates="agent_calls", lazy="joined")
423423
# Which agent (registry id: "scope", "implement", …) made this call — the
424424
# timeline's grouping label. An agent is what makes a call, so there is no
425425
# unattributed one: the row is written from the registered agent's own id.

‎backend/druks/models.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import TYPE_CHECKING, Any, ClassVar, Self
55

66
from sqlalchemy import DateTime, Integer, cast, select
7+
from sqlalchemy.ext.asyncio import AsyncAttrs
78
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
89
from sqlalchemy.types import TypeDecorator
910

@@ -29,7 +30,7 @@ def process_result_value(self, value: datetime | None, dialect: Any) -> datetime
2930
return ensure_utc(value) if value else value
3031

3132

32-
class Base(DeclarativeBase):
33+
class Base(AsyncAttrs, DeclarativeBase):
3334
# Every ``Mapped[datetime]`` column stores tz-aware UTC — the decorator
3435
# guarantees aware values on read (writes are unaffected). Mapping it here
3536
# means models declare ``Mapped[datetime]`` with no per-column type.

‎backend/druks/skills/models.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SkillCollection(Base, Uuid7Pk):
2121
skills: Mapped[list["Skill"]] = relationship(
2222
back_populates="collection",
2323
cascade="all, delete-orphan",
24+
lazy="selectin",
2425
order_by="Skill.name",
2526
)
2627

@@ -64,7 +65,7 @@ class Skill(Base, Uuid7Pk):
6465

6566
name: Mapped[str] = mapped_column(String, unique=True)
6667
description: Mapped[str] = mapped_column(String, default="")
67-
collection: Mapped[SkillCollection] = relationship(back_populates="skills")
68+
collection: Mapped[SkillCollection] = relationship(back_populates="skills", lazy="raise_on_sql")
6869
collection_id: Mapped[str] = mapped_column(ForeignKey("skill_collections.id"))
6970
# Disabled skills stay on disk but the delivery projection excludes them
7071
# from every sandbox upload.

0 commit comments

Comments
 (0)