Fixed warning: SAWarning: Coercing Subquery object into a select() for use in IN()

This commit is contained in:
Igor Miagkov
2022-12-29 19:45:07 +04:00
committed by Andreas Köpf
parent 65dbb9c4e1
commit acfcd7b8d2
+2 -2
View File
@@ -397,7 +397,7 @@ class PromptRepository:
distinct_threads = distinct_threads.filter(Post.role == require_role)
distinct_threads = distinct_threads.subquery()
random_thread = self.db.query(distinct_threads).order_by(func.random()).limit(1).subquery()
random_thread = self.db.query(distinct_threads).order_by(func.random()).limit(1)
thread_posts = self.db.query(Post).filter(Post.thread_id.in_(random_thread)).all()
return thread_posts
@@ -443,7 +443,7 @@ class PromptRepository:
if post_role:
parent = parent.filter(Post.role == post_role)
parent = parent.order_by(func.random()).limit(1).subquery()
parent = parent.order_by(func.random()).limit(1)
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)