Skip to content

Commit

Permalink
Fix: SAWarning: Coercing Subquery object into a select() for use in I…
Browse files Browse the repository at this point in the history
…N() - endless warning :)
  • Loading branch information
Jan Polonsky committed Aug 26, 2024
1 parent d71adbe commit c842629
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 c842629

Please sign in to comment.