Skip to content

Commit

Permalink
fix: don't allow blank tag alias values in db (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanVoxel authored Dec 9, 2024
1 parent a535ed1 commit aaea0b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tagstudio/src/core/library/alchemy/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def migrate_json_to_sqlite(self, json_lib: JsonLibrary):
# Tag Aliases
for tag in json_lib.tags:
for alias in tag.aliases:
if not alias:
break
self.add_alias(name=alias, tag_id=tag.id)

# Tag Subtags
Expand Down Expand Up @@ -1015,6 +1017,9 @@ def add_subtag(self, parent_id: int, child_id: int) -> bool:

def add_alias(self, name: str, tag_id: int) -> bool:
with Session(self.engine) as session:
if not name:
logger.warning("[LIBRARY][add_alias] Alias value must not be empty")
return False
alias = TagAlias(
name=name,
tag_id=tag_id,
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/core/library/alchemy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TagAlias(Base):

id: Mapped[int] = mapped_column(primary_key=True)

name: Mapped[str]
name: Mapped[str] = mapped_column(nullable=False)

tag_id: Mapped[int] = mapped_column(ForeignKey("tags.id"))
tag: Mapped["Tag"] = relationship(back_populates="aliases")
Expand Down
2 changes: 1 addition & 1 deletion tagstudio/src/qt/widgets/migration_modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def check_alias_parity(self) -> bool:
sql_aliases = set(
session.scalars(select(TagAlias.name).where(TagAlias.tag_id == tag.id))
)
json_aliases = set(self.json_lib.get_tag(tag_id).aliases)
json_aliases = set([x for x in self.json_lib.get_tag(tag_id).aliases if x])

logger.info(
"[Alias Parity]",
Expand Down

0 comments on commit aaea0b1

Please sign in to comment.