From fe959573eca1bcb3a134fcc7c935b5152331266e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 10 Jul 2022 16:29:47 +0200 Subject: [PATCH] fix 500 errors --- files/helpers/alerts.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 11884e01df..ce780dcb9c 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -48,8 +48,18 @@ def notif_comment(text): text_html = sanitize(text) - existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() - + try: existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() + except: + existing = g.db.query(Comment).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).all() + + notifs = g.db.query(Notification).filter(Notification.comment_id.in_([x.id for x in existing])).all() + for c in notifs: g.db.delete(c) + g.db.flush() + + for c in existing: g.db.delete(c) + g.db.flush() + existing = g.db.query(Comment.id).filter_by(author_id=AUTOJANNY_ID, parent_submission=None, body_html=text_html, is_bot=True).one_or_none() + if existing: return existing[0] else: return create_comment(text_html)