From dec9efc49bac8c9899dfa817503d1aefeadd596e Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Sat, 26 Nov 2022 02:35:26 +0300 Subject: [PATCH] fix double prepend --- resolvers/inbox/chats.py | 14 ++++++++------ resolvers/zine/topics.py | 11 ++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/resolvers/inbox/chats.py b/resolvers/inbox/chats.py index e24acf0c..b11546d8 100644 --- a/resolvers/inbox/chats.py +++ b/resolvers/inbox/chats.py @@ -63,12 +63,14 @@ async def create_chat(_, info, title="", members=[]): cids = await redis.execute("SMEMBERS", f"chats_by_user/{user.slug}") for cid in cids: c = await redis.execute("GET", F"chats/{cid.decode('utf-8')}") - isc = [x for x in c["users"] if x not in chat["users"]] - if isc == [] and chat["title"] == c["title"]: - return { - "error": "chat was created before", - "chat": chat - } + if c: + c = json.loads(c) + isc = [x for x in c["users"] if x not in chat["users"]] + if isc == [] and chat["title"] == c["title"]: + return { + "error": "chat was created before", + "chat": chat + } for m in members: await redis.execute("SADD", f"chats_by_user/{m}", chat_id) diff --git a/resolvers/zine/topics.py b/resolvers/zine/topics.py index 81db4f91..6edb3c09 100644 --- a/resolvers/zine/topics.py +++ b/resolvers/zine/topics.py @@ -98,11 +98,12 @@ async def topic_follow(user, slug): async def topic_unfollow(user, slug): with local_session() as session: sub = ( - session.query(TopicFollower) - .filter( - and_(TopicFollower.follower == user.slug, TopicFollower.topic == slug) - ) - .first() + session.query(TopicFollower).filter( + and_( + TopicFollower.follower == user.slug, + TopicFollower.topic == slug + ) + ).first() ) if not sub: raise Exception("[resolvers.topics] follower not exist")