create-shout-fix2

This commit is contained in:
Untone 2025-01-21 18:28:03 +03:00
parent 1ed185a701
commit 8432a00691
2 changed files with 16 additions and 16 deletions

View File

@ -113,13 +113,13 @@ async def create_shout(_, info, inp):
logger.info(f"Creating shout with slug: {slug}") logger.info(f"Creating shout with slug: {slug}")
# Создаем объект Shout напрямую, без промежуточного словаря # Правильно:
new_shout = Shout({ new_shout = Shout(
**inp, **inp, # распаковываем входные данные
"slug": slug, slug=slug, # явно указываем именованные аргументы
"created_by": author_id, created_by=author_id,
"created_at": current_time created_at=current_time,
}) )
# Check for duplicate slug # Check for duplicate slug
logger.debug(f"Checking for existing slug: {slug}") logger.debug(f"Checking for existing slug: {slug}")
@ -195,7 +195,7 @@ async def create_shout(_, info, inp):
try: try:
author = session.query(Author).filter(Author.id == author_id).first() author = session.query(Author).filter(Author.id == author_id).first()
if author and author.stat: if author and author.stat:
author.stat["shouts"] = (author.stat.get("shouts", 0) + 1) author.stat["shouts"] = author.stat.get("shouts", 0) + 1
session.add(author) session.add(author)
session.commit() session.commit()
await cache_author(author.dict()) await cache_author(author.dict())