published-at-fix2
This commit is contained in:
@@ -214,10 +214,20 @@ def get_shouts_with_links(info: GraphQLResolveInfo, q: Select, limit: int = 20,
|
|||||||
if hasattr(row, "Shout"):
|
if hasattr(row, "Shout"):
|
||||||
shout = row.Shout
|
shout = row.Shout
|
||||||
# logger.debug(f"Processing shout#{shout.id} at index {idx}")
|
# logger.debug(f"Processing shout#{shout.id} at index {idx}")
|
||||||
if shout:
|
else:
|
||||||
|
# 🔍 Диагностика: логируем случаи когда row не содержит Shout
|
||||||
|
logger.warning(f"Row {idx} does not have 'Shout' attribute. Row attributes: {dir(row)}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if shout and shout.id is not None:
|
||||||
shout_id = int(f"{shout.id}")
|
shout_id = int(f"{shout.id}")
|
||||||
shout_dict = shout.dict()
|
shout_dict = shout.dict()
|
||||||
|
|
||||||
|
# 🔍 Убеждаемся что id присутствует в словаре
|
||||||
|
if not shout_dict.get("id"):
|
||||||
|
logger.error(f"Shout dict missing id field for shout#{shout_id}")
|
||||||
|
continue
|
||||||
|
|
||||||
# Обработка поля created_by
|
# Обработка поля created_by
|
||||||
if has_field(info, "created_by"):
|
if has_field(info, "created_by"):
|
||||||
main_author_id = shout_dict.get("created_by")
|
main_author_id = shout_dict.get("created_by")
|
||||||
@@ -426,8 +436,13 @@ async def get_shout(_: None, info: GraphQLResolveInfo, slug: str = "", shout_id:
|
|||||||
shouts = get_shouts_with_links(info, q, limit=1)
|
shouts = get_shouts_with_links(info, q, limit=1)
|
||||||
|
|
||||||
# Возвращаем первую (и единственную) публикацию, если она найдена
|
# Возвращаем первую (и единственную) публикацию, если она найдена
|
||||||
if shouts:
|
if shouts and len(shouts) > 0 and shouts[0] is not None:
|
||||||
return shouts[0]
|
# 🔍 Дополнительная проверка что объект имеет id
|
||||||
|
shout = shouts[0]
|
||||||
|
if (hasattr(shout, "get") and shout.get("id")) or (hasattr(shout, "id") and shout.id):
|
||||||
|
return shout
|
||||||
|
logger.error(f"get_shout: Found shout without valid id: {shout}")
|
||||||
|
return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
@@ -528,10 +543,18 @@ async def load_shouts_search(
|
|||||||
logger.debug(f"[load_shouts_search] Database returned {len(shouts)} shouts")
|
logger.debug(f"[load_shouts_search] Database returned {len(shouts)} shouts")
|
||||||
shouts_dicts: list[dict[str, Any]] = []
|
shouts_dicts: list[dict[str, Any]] = []
|
||||||
for shout in shouts:
|
for shout in shouts:
|
||||||
|
# 🔍 Фильтруем None значения и объекты без id
|
||||||
|
if shout is None:
|
||||||
|
logger.warning("[load_shouts_search] Skipping None shout object")
|
||||||
|
continue
|
||||||
|
|
||||||
shout_dict = shout.dict()
|
shout_dict = shout.dict()
|
||||||
shout_id_str = shout_dict.get("id")
|
shout_id_str = shout_dict.get("id")
|
||||||
if shout_id_str:
|
if not shout_id_str:
|
||||||
shout_dict["score"] = scores.get(shout_id_str, 0.0)
|
logger.warning(f"[load_shouts_search] Skipping shout without id: {shout_dict}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
shout_dict["score"] = scores.get(str(shout_id_str), 0.0)
|
||||||
shouts_dicts.append(shout_dict)
|
shouts_dicts.append(shout_dict)
|
||||||
|
|
||||||
shouts_dicts.sort(key=lambda x: x.get("score", 0.0), reverse=True)
|
shouts_dicts.sort(key=lambda x: x.get("score", 0.0), reverse=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user