Skip to content

Commit

Permalink
Merge pull request #352 from Progress1/warn_in
Browse files Browse the repository at this point in the history
Fix: SAWarning: Coercing Subquery object into a select()
  • Loading branch information
Progress1 authored Aug 26, 2024
2 parents d71adbe + c842629 commit 498a814
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
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()

0 comments on commit 498a814

Please sign in to comment.