diff --git a/backend/oasst_backend/exceptions.py b/backend/oasst_backend/exceptions.py index 98224790..c1a7bd2e 100644 --- a/backend/oasst_backend/exceptions.py +++ b/backend/oasst_backend/exceptions.py @@ -34,6 +34,7 @@ class OasstErrorCode(IntEnum): INVALID_TASK_TYPE = 2004 USER_NOT_SPECIFIED = 2005 NO_THREADS_FOUND = 2006 + NO_REPLIES_FOUND = 2007 WORK_PACKAGE_NOT_FOUND = 2100 WORK_PACKAGE_EXPIRED = 2101 WORK_PACKAGE_PAYLOAD_TYPE_MISMATCH = 2102 diff --git a/backend/oasst_backend/prompt_repository.py b/backend/oasst_backend/prompt_repository.py index 6d44c443..95e7867e 100644 --- a/backend/oasst_backend/prompt_repository.py +++ b/backend/oasst_backend/prompt_repository.py @@ -445,6 +445,8 @@ class PromptRepository: parent = parent.order_by(func.random()).limit(1).subquery() replies = self.db.query(Post).filter(Post.parent_id.in_(parent)).order_by(func.random()).limit(max_size).all() + if not replies: + raise OasstError("No replies found", OasstErrorCode.NO_REPLIES_FOUND) thread = self.fetch_thread(replies[0].thread_id) thread = {p.id: p for p in thread}