Skip to content

Commit 8b2115f

Browse files
authored
fix: prevent MissingGreenlet error on task board query (#20)
Change sub_tasks, comments, and parent_task relationships to lazy="noload" to avoid recursive selectin loading that breaks the async greenlet context. Guard to_dict() counts against unloaded relationships.
1 parent 3c51a1e commit 8b2115f

File tree

1 file changed

+5
-5
lines changed
  • server/src/flowforge_server/db/models

1 file changed

+5
-5
lines changed

server/src/flowforge_server/db/models/task.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ class Task(Base, TimestampMixin):
165165
"User", foreign_keys=[created_by_user_id], lazy="selectin"
166166
)
167167
parent_task: Mapped["Task | None"] = relationship(
168-
"Task", remote_side=[id], foreign_keys=[parent_task_id]
168+
"Task", remote_side=[id], foreign_keys=[parent_task_id], lazy="noload"
169169
)
170170
sub_tasks: Mapped[list["Task"]] = relationship(
171-
"Task", foreign_keys=[parent_task_id], lazy="selectin"
171+
"Task", foreign_keys=[parent_task_id], lazy="noload"
172172
)
173173
comments: Mapped[list["Comment"]] = relationship(
174-
"Comment", back_populates="task", lazy="selectin"
174+
"Comment", back_populates="task", lazy="noload"
175175
)
176176

177177
def __repr__(self) -> str:
@@ -215,8 +215,8 @@ def to_dict(self) -> dict[str, Any]:
215215
"parent_task_id": str(self.parent_task_id) if self.parent_task_id else None,
216216
"function_id": str(self.function_id) if self.function_id else None,
217217
"run_id": str(self.run_id) if self.run_id else None,
218-
"sub_tasks_count": len(self.sub_tasks) if self.sub_tasks else 0,
219-
"comments_count": len(self.comments) if self.comments else 0,
218+
"sub_tasks_count": len(self.sub_tasks) if "sub_tasks" in self.__dict__ and self.sub_tasks else 0,
219+
"comments_count": len(self.comments) if "comments" in self.__dict__ and self.comments else 0,
220220
"metadata": self.task_metadata,
221221
"created_at": self.created_at.isoformat() if self.created_at else None,
222222
"updated_at": self.updated_at.isoformat() if self.updated_at else None,

0 commit comments

Comments
 (0)