rollback-тесты на urllib из-за нестабильности httpx через docker-proxy на win

This commit is contained in:
2026-10-01 02:57:49 +03:00
parent f3a6f7a62f
commit 14ec627341
4 changed files with 97 additions and 58 deletions
+21 -13
View File
@@ -10,20 +10,28 @@ from ..db.models import Chat, ChatMember, User
async def create_atomic(
db: AsyncSession, title: str, member_ids: list[UUID]
) -> Chat:
async with db.begin():
found = (
(await db.execute(select(User.id).where(User.id.in_(member_ids))))
.scalars()
.all()
)
if len(set(found)) != len(set(member_ids)):
raise ValueError("member_not_found")
# проверка всех участников
found = (
(await db.execute(select(User.id).where(User.id.in_(member_ids))))
.scalars()
.all()
)
if len(set(found)) != len(set(member_ids)):
await db.rollback()
raise ValueError("member_not_found")
chat = Chat(title=title)
db.add(chat)
await db.flush()
for uid in member_ids:
db.add(ChatMember(chat_id=chat.id, user_id=uid))
chat = Chat(title=title)
db.add(chat)
await db.flush() # получить chat.id
for uid in member_ids:
db.add(ChatMember(chat_id=chat.id, user_id=uid))
try:
await db.commit()
except Exception:
await db.rollback()
raise
await db.refresh(chat)
return chat