From 70501d49b0adefc476bbcef39f208a09b9847990 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 3 Dec 2022 10:37:45 +0300 Subject: [PATCH] trcbk-devmode-only --- resolvers/zine/load.py | 30 ++++++++++++++++-------------- server.py | 7 ++++++- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/resolvers/zine/load.py b/resolvers/zine/load.py index 34ff0ead..f70e8960 100644 --- a/resolvers/zine/load.py +++ b/resolvers/zine/load.py @@ -5,6 +5,7 @@ from sqlalchemy.sql.expression import desc, asc, select, func from auth.credentials import AuthCredentials from base.orm import local_session from base.resolvers import query +from base.exceptions import ObjectNotExist from orm import ViewedEntry from orm.shout import Shout, ShoutAuthor from orm.reaction import Reaction @@ -58,22 +59,23 @@ async def load_shout(_, info, slug): ).filter( Shout.deletedAt.is_(None) ).group_by(Shout.id) + try: + [shout, viewed_stat, reacted_stat, commented_stat, rating_stat] = session.execute(q).first() - [shout, viewed_stat, reacted_stat, commented_stat, rating_stat] = session.execute(q).unique().one() + shout.stat = { + "viewed": viewed_stat, + "reacted": reacted_stat, + "commented": commented_stat, + "rating": rating_stat + } - shout.stat = { - "viewed": viewed_stat, - "reacted": reacted_stat, - "commented": commented_stat, - "rating": rating_stat - } - - for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug): - for author in shout.authors: - if author.id == author_caption.user: - author.caption = author_caption.caption - - return shout + for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug): + for author in shout.authors: + if author.id == author_caption.user: + author.caption = author_caption.caption + return shout + except Exception: + raise ObjectNotExist("Slug was not found: %s" % slug) @query.field("loadShouts") diff --git a/server.py b/server.py index a1443810..f7cc4188 100644 --- a/server.py +++ b/server.py @@ -4,6 +4,11 @@ import uvicorn from settings import PORT, DEV_SERVER_STATUS_FILE_NAME + +def exception_handler(exception_type, exception, traceback, debug_hook=sys.excepthook): + print("%s: %s" % (exception_type.__name__, exception)) + + log_settings = { 'version': 1, 'disable_existing_loggers': True, @@ -66,7 +71,6 @@ if __name__ == "__main__": if x == "dev": if os.path.exists(DEV_SERVER_STATUS_FILE_NAME): os.remove(DEV_SERVER_STATUS_FILE_NAME) - want_reload = False if "reload" in sys.argv: print("MODE: DEV + RELOAD") @@ -90,6 +94,7 @@ if __name__ == "__main__": migrate() else: + sys.excepthook = exception_handler uvicorn.run( "main:app", host="0.0.0.0",