From 1bce1c273f412cb2d020ca4b8712fcca9606fcef Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 7 Jun 2022 12:32:48 +0200 Subject: [PATCH] no more 500 error --- files/routes/reporting.py | 40 ++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index 4b4fe600c..699bedb1c 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -101,19 +101,20 @@ def remove_report_post(v, pid, uid): uid = int(uid) except: abort(400) - report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one() - - g.db.delete(report) + report = g.db.query(Flag).filter_by(post_id=pid, user_id=uid).one_or_none() - ma=ModAction( - kind="delete_report", - user_id=v.id, - target_submission_id=pid - ) + if report: + g.db.delete(report) - g.db.add(ma) + ma=ModAction( + kind="delete_report", + user_id=v.id, + target_submission_id=pid + ) - g.db.commit() + g.db.add(ma) + + g.db.commit() return {"message": "Report removed successfully!"} @@ -126,18 +127,19 @@ def remove_report_comment(v, cid, uid): cid = int(cid) uid = int(uid) - report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one() + report = g.db.query(CommentFlag).filter_by(comment_id=cid, user_id=uid).one_or_none() - g.db.delete(report) + if report: + g.db.delete(report) - ma=ModAction( - kind="delete_report", - user_id=v.id, - target_comment_id=cid - ) + ma=ModAction( + kind="delete_report", + user_id=v.id, + target_comment_id=cid + ) - g.db.add(ma) + g.db.add(ma) - g.db.commit() + g.db.commit() return {"message": "Report removed successfully!"} \ No newline at end of file