diff --git a/resolvers/draft.py b/resolvers/draft.py index a6b28f67..02f5e084 100644 --- a/resolvers/draft.py +++ b/resolvers/draft.py @@ -79,7 +79,7 @@ async def load_drafts(_, info): Returns: dict: Список черновиков или сообщение об ошибке """ - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") if not author_id: @@ -152,7 +152,7 @@ async def create_draft(_, info, draft_input): ... assert result['draft'].title == 'Test' ... return result """ - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") if not author_id: @@ -226,7 +226,7 @@ async def update_draft(_, info, draft_id: int, draft_input): Returns: dict: Обновленный черновик или сообщение об ошибке """ - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") if not author_id: @@ -328,7 +328,7 @@ async def update_draft(_, info, draft_id: int, draft_input): @mutation.field("delete_draft") @login_required async def delete_draft(_, info, draft_id: int): - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") with local_session() as session: @@ -387,7 +387,7 @@ async def publish_draft(_, info, draft_id: int): Returns: dict: Результат публикации с shout или сообщением об ошибке """ - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") if not author_id: @@ -490,7 +490,7 @@ async def unpublish_draft(_, info, draft_id: int): Returns: dict: Результат операции с информацией о черновике или сообщением об ошибке """ - author_dict = info.context.get("author", {}) + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") if author_id: diff --git a/resolvers/editor.py b/resolvers/editor.py index 41539c7d..e5a64876 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -135,7 +135,7 @@ async def get_my_shout(_, info, shout_id: int): @query.field("get_shouts_drafts") @login_required async def get_shouts_drafts(_, info): - author_dict = info.context.get("author") + author_dict = info.context.get("author") or {} if not author_dict: return {"error": "author profile was not found"} author_id = author_dict.get("id") @@ -158,7 +158,7 @@ async def get_shouts_drafts(_, info): # @login_required async def create_shout(_, info, inp): logger.info(f"Starting create_shout with input: {inp}") - author_dict = info.context.get("author") + author_dict = info.context.get("author") or {} logger.debug(f"Context author: {author_dict}") if not author_dict: @@ -385,7 +385,8 @@ def patch_topics(session, shout, topics_input): # @mutation.field("update_shout") # @login_required async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): - author_id = info.context.get("author").get("id") + author_dict = info.context.get("author") or {} + author_id = author_dict.get("id") if not author_id: logger.error("Unauthorized update attempt") return {"error": "unauthorized"} @@ -597,7 +598,7 @@ async def update_shout(_, info, shout_id: int, shout_input=None, publish=False): # @mutation.field("delete_shout") # @login_required async def delete_shout(_, info, shout_id: int): - author_dict = info.context.get("author") + author_dict = info.context.get("author") or {} if not author_dict: return {"error": "author profile was not found"} author_id = author_dict.get("id") diff --git a/resolvers/follower.py b/resolvers/follower.py index c6dcb403..c50550f3 100644 --- a/resolvers/follower.py +++ b/resolvers/follower.py @@ -30,7 +30,7 @@ async def follow(_, info, what, slug="", entity_id=0): viewer_id = info.context.get("author", {}).get("id") if not viewer_id: return {"error": "Access denied"} - follower_dict = info.context.get("author") + follower_dict = info.context.get("author") or {} logger.debug(f"follower: {follower_dict}") if not viewer_id or not follower_dict: @@ -151,7 +151,7 @@ async def unfollow(_, info, what, slug="", entity_id=0): viewer_id = info.context.get("author", {}).get("id") if not viewer_id: return GraphQLError("Access denied") - follower_dict = info.context.get("author") + follower_dict = info.context.get("author") or {} logger.debug(f"follower: {follower_dict}") if not viewer_id or not follower_dict: diff --git a/resolvers/notifier.py b/resolvers/notifier.py index 08b7f2d4..4a33740c 100644 --- a/resolvers/notifier.py +++ b/resolvers/notifier.py @@ -203,7 +203,7 @@ def get_notifications_grouped(author_id: int, after: int = 0, limit: int = 10, o @query.field("load_notifications") @login_required async def load_notifications(_, info, after: int, limit: int = 50, offset=0): - author_dict = info.context.get("author") + author_dict = info.context.get("author") or {} author_id = author_dict.get("id") error = None total = 0 diff --git a/resolvers/reaction.py b/resolvers/reaction.py index 0728ac4f..e31711b2 100644 --- a/resolvers/reaction.py +++ b/resolvers/reaction.py @@ -83,7 +83,7 @@ def get_reactions_with_stat(q, limit=10, offset=0): reactions = [] with local_session() as session: - result_rows = session.execute(q) + result_rows = session.execute(q).unique() for reaction, author, shout, comments_count, rating_stat in result_rows: # Пропускаем реакции с отсутствующими shout или author if not shout or not author: