From 5e2842774a45482a8e5bec7ff36cb6fdcdf2bcd6 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 28 Jan 2025 15:38:10 +0300 Subject: [PATCH] media-field-workarounds --- resolvers/editor.py | 13 +++++++++++++ services/schema.py | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resolvers/editor.py b/resolvers/editor.py index c75cf406..89ca3e16 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -1,3 +1,4 @@ +import json import time from sqlalchemy import and_, desc, select @@ -52,6 +53,18 @@ async def get_my_shout(_, info, shout_id: int): if not shout: return {"error": "no shout found", "shout": None} + # Преобразуем media JSON в список объектов MediaItem + if hasattr(shout, "media") and shout.media: + if isinstance(shout.media, str): + try: + shout.media = json.loads(shout.media) + except: + shout.media = [] + if not isinstance(shout.media, list): + shout.media = [shout.media] if shout.media else [] + else: + shout.media = [] + logger.debug(f"got {len(shout.authors)} shout authors, created by {shout.created_by}") is_editor = "editor" in roles logger.debug(f'viewer is{'' if is_editor else ' not'} editor') diff --git a/services/schema.py b/services/schema.py index 448b63b5..9848c190 100644 --- a/services/schema.py +++ b/services/schema.py @@ -13,7 +13,7 @@ resolvers = [query, mutation] async def request_graphql_data(gql, url=AUTH_URL, headers=None): """ Выполняет GraphQL запрос к указанному URL - + :param gql: GraphQL запрос :param url: URL для запроса, по умолчанию AUTH_URL :param headers: Заголовки запроса @@ -37,5 +37,6 @@ async def request_graphql_data(gql, url=AUTH_URL, headers=None): logger.error(f"{url}: {response.status_code} {response.text}") except Exception as _e: import traceback + logger.error(f"request_graphql_data error: {traceback.format_exc()}") return None