Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: SAWarning: Coercing Subquery object into a select() #352

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/core/model/tag_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 11 additions & 5 deletions src/core/model/word_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Loading