Skip to content

Commit

Permalink
fix: incorrect orm operation
Browse files Browse the repository at this point in the history
  • Loading branch information
dantetemplar committed Jan 20, 2025
1 parent aa36737 commit 74cae90
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/modules/event_groups/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,21 @@ async def delete_by_tag_alias(self, tag_alias: str) -> int:
return 0

async with self._create_session() as session:
q = delete(EventGroup.tags_association).where(EventGroup.tags_association.c.tag_id == tag.id)
deleted = await session.execute(q)
# select event groups with that tag
q = (
select(EventGroup.id)
.join(EventGroup.tags_association)
.where(EventGroup.tags_association.any(tag_id=tag.id))
)
event_group_ids = (await session.execute(q)).scalars().all()
if not event_group_ids:
return 0

# delete event groups
q = delete(EventGroup).where(EventGroup.id.in_(event_group_ids))
await session.execute(q)
await session.commit()
return cast(deleted.rowcount, int)
return len(event_group_ids)

# ^^^^^^^^^^^^^^^^^ CRUD ^^^^^^^^^^^^^^^^^ #

Expand Down

0 comments on commit 74cae90

Please sign in to comment.