From c842629d4d1c5245315d7583fff1acb48227cb1b Mon Sep 17 00:00:00 2001 From: Jan Polonsky Date: Mon, 26 Aug 2024 15:35:44 +0200 Subject: [PATCH] Fix: SAWarning: Coercing Subquery object into a select() for use in IN() - endless warning :) --- src/core/model/tag_cloud.py | 17 ++++++++++++----- src/core/model/word_list.py | 16 +++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/core/model/tag_cloud.py b/src/core/model/tag_cloud.py index 52542be0c..07c0fba95 100644 --- a/src/core/model/tag_cloud.py +++ b/src/core/model/tag_cloud.py @@ -42,11 +42,18 @@ def add_tag_clouds(cls, tag_clouds): def get_grouped_words(cls, tag_cloud_day): day_filter = (datetime.datetime.now() - datetime.timedelta(days=tag_cloud_day)).date() stopwords = WordListEntry.stopwords_subquery() - grouped_words = db.session.query(TagCloud.word, - label('word_quantity', func.sum(TagCloud.word_quantity))).filter( - TagCloud.collected == day_filter).filter( - func.lower(TagCloud.word).notin_(stopwords)).group_by(TagCloud.word).order_by( - db.desc('word_quantity')).limit(100).all() + grouped_words = db.session.query( + TagCloud.word, + label('word_quantity', func.sum(TagCloud.word_quantity)) + ).filter( + TagCloud.collected == day_filter + ).filter( + func.lower(TagCloud.word).notin_(stopwords) + ).group_by( + TagCloud.word + ).order_by( + db.desc('word_quantity') + ).limit(100).all() grouped_words_schema = GroupedWordsSchema(many=True) return grouped_words_schema.dump(grouped_words) diff --git a/src/core/model/word_list.py b/src/core/model/word_list.py index 5e45f43eb..3b9e001f5 100644 --- a/src/core/model/word_list.py +++ b/src/core/model/word_list.py @@ -217,9 +217,15 @@ def update_word_list_entries(cls, id, name, entries): @classmethod def stopwords_subquery(cls): - return db.session.query(func.lower(WordListEntry.value)).distinct().group_by(WordListEntry.value).join( - WordListCategory, - WordListCategory.id == WordListEntry.word_list_category_id).join( - WordList, WordList.id == WordListCategory.word_list_id).filter( - WordList.use_for_stop_words == True).subquery() + return db.session.query( + func.lower(WordListEntry.value) + ).distinct().group_by( + WordListEntry.value + ).join( + WordListCategory, WordListCategory.id == WordListEntry.word_list_category_id + ).join( + WordList, WordList.id == WordListCategory.word_list_id + ).filter( + WordList.use_for_stop_words == True + ).scalar_subquery()