From f12d2fc560b2796afa7c46feb40471c0dba6c169 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 26 Feb 2024 01:03:11 +0300 Subject: [PATCH] get-author-fix --- resolvers/author.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/resolvers/author.py b/resolvers/author.py index 69898a1b..7be38735 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -1,7 +1,7 @@ import json import time -from sqlalchemy import select, or_, and_, text, desc +from sqlalchemy import select, or_, and_, text, desc, cast, Integer from sqlalchemy.orm import aliased from sqlalchemy_searchable import search @@ -45,18 +45,16 @@ async def get_author(_, _info, slug='', author_id=None): if slug: with local_session() as session: - aliased_author = aliased(Author) - q = select(aliased_author).filter(aliased_author.slug == slug) + q = select(Author).filter(Author.slug == slug) [author] = session.execute(q) - author_id = aliased_author.id + author_id = cast(Author.id, Integer) if author_id: cache = await redis.execute('GET', f'id:{author_id}:author') author = json.loads(cache) if not author: - aliased_author = aliased(Author) - q = select(aliased_author).where(aliased_author.id == author_id) + q = select(Author).where(Author.id == author_id) [author] = get_with_stat(q) if author: await update_author_cache(author.dict())