Skip to content

Commit

Permalink
fix(AUTOFILL macro): error when trying to add tag with name that alre…
Browse files Browse the repository at this point in the history
…ady exists
  • Loading branch information
Computerdores committed Nov 29, 2024
1 parent 191ed29 commit 5c7c34d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def add_entry_field_type(
if value:
assert isinstance(value, list)
for tag in value:
field_model.tags.add(Tag(name=tag))
field_model.tags.add(self.get_tag_by_name(tag) or Tag(name=tag))

elif field.type == FieldTypeEnum.DATETIME:
field_model = DatetimeField(
Expand Down Expand Up @@ -870,6 +870,15 @@ def get_tag(self, tag_id: int) -> Tag:

return tag

def get_tag_by_name(self, tag_name: str) -> Tag | None:
with Session(self.engine) as session:
statement = (
select(Tag)
.outerjoin(TagAlias)
.where(or_(Tag.name == tag_name, TagAlias.name == tag_name))
)
return session.scalar(statement)

def get_alias(self, tag_id: int, alias_id: int) -> TagAlias:
with Session(self.engine) as session:
alias_query = select(TagAlias).where(TagAlias.id == alias_id, TagAlias.tag_id == tag_id)
Expand Down

0 comments on commit 5c7c34d

Please sign in to comment.