Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/tagstudio/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,35 +1170,29 @@ def update_entry_path(self, entry_id: int | Entry, path: Path) -> bool:
session.commit()
return True

def remove_tag(self, tag_id: int):
def remove_tag(self, tag_id: int) -> bool:
with Session(self.engine, expire_on_commit=False) as session:
try:
aliases = session.scalars(select(TagAlias).where(TagAlias.tag_id == tag_id))
for alias in aliases:
session.delete(alias)
session.flush()

tag_parents = session.scalars(
select(TagParent).where(TagParent.parent_id == tag_id)
).all()
for tag_parent in tag_parents:
session.delete(tag_parent)
session.flush()

disam_stmt = (
session.execute(delete(TagAlias).where(TagAlias.tag_id == tag_id))
session.execute(delete(TagEntry).where(TagEntry.tag_id == tag_id))
session.execute(
delete(TagParent).where(
or_(TagParent.child_id == tag_id, TagParent.parent_id == tag_id)
)
)
session.execute(
update(Tag)
.where(Tag.disambiguation_id == tag_id)
.values(disambiguation_id=None)
)
session.execute(disam_stmt)
session.flush()

session.query(Tag).filter_by(id=tag_id).delete()
session.execute(delete(Tag).where(Tag.id == tag_id))
session.commit()

except IntegrityError as e:
logger.error(e)
session.rollback()
return False
return True

def update_field_position(
self,
Expand Down