diff --git a/resolvers/author.py b/resolvers/author.py index be15e794..01bc24d6 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -43,8 +43,9 @@ async def get_author(_, _info, slug='', author_id=None): try: if slug: q = select(Author).select_from(Author).filter(Author.slug == slug) - [author] = get_with_stat(q) - if author: + result = get_with_stat(q) + if result: + [author] = result author_id = author.id if author_id: @@ -55,8 +56,10 @@ async def get_author(_, _info, slug='', author_id=None): if cache: author_dict = json.loads(cache) else: - [author] = get_with_stat(q) - author_dict = author.dict() + result = get_with_stat(q) + if result: + [author] = result + author_dict = author.dict() logger.debug(f'author to be stored: {author_dict}') if author: await set_author_cache(author_dict) @@ -85,9 +88,9 @@ async def get_author_by_user_id(user_id: str): return author q = select(Author).filter(Author.user == user_id) - - [author] = get_with_stat(q) - if author: + result = get_with_stat(q) + if result: + [author] = result await set_author_cache(author.dict()) except Exception as exc: import traceback diff --git a/services/cache.py b/services/cache.py index 5da2b50c..5365ae37 100644 --- a/services/cache.py +++ b/services/cache.py @@ -133,8 +133,10 @@ def after_reaction_insert(mapper, connection, reaction: Reaction): @event.listens_for(Author, 'after_update') def after_author_update(mapper, connection, author: Author): q = select(Author).where(Author.id == author.id) - [author_with_stat] = get_with_stat(q) - asyncio.create_task(set_author_cache(author_with_stat.dict())) + result = get_with_stat(q) + if result: + [author_with_stat] = result + asyncio.create_task(set_author_cache(author_with_stat.dict())) @event.listens_for(TopicFollower, 'after_insert')