Skip to content

[Bug]: Tag parent relationship can remain after child is deleted #1419

Description

@CyanVoxel

Checklist

  • I am using an up-to-date version.
  • I have read the documentation.
  • I have searched existing issues.

TagStudio Version

Alpha v9.6.0/main

Operating System & Version

Windows 11

Description

(Reporting on behalf of someone else on Discord) There's been a case of a tag parent relationship remaining in the database after a child tag in the relationship has been deleted. I can't currently reproduce the issue myself but have verified the extraneous relationship inside the DB. Note that this is the inverse issue that the DB 102 migration corrects for.

Quick info about the affected DB:

  • Example of invalid relationship: parent_id 1038, child_id 1107
  • Tag 1107 does not exist in the DB
  • DB was created with version 102

This issue presents as strange tag search behavior, which can range from results that don't update to no results at all.
Image
Image

Discord thread: https://discord.com/channels/1229183630228848661/1522240701675606077

Affected library: https://cdn.discordapp.com/attachments/1522240701675606077/1522598055667568791/ts_library.sqlite?ex=6a490d70&is=6a47bbf0&hm=74c161e11cd5109ef2abdae305d900628a109c4543a6372cd2ac7bb3ebf880c0&

While it should be trivial to patch any existing libraries that are affected by this, finding the root cause and determining if it's still an active issue is critically important.

Expected Behavior

Tag parent relationships should be removed if either the parent or child tags referenced are deleted.

Steps to Reproduce

Currently unknown

Logs

Taken from my machine on main:

Traceback (most recent call last):
  File "/Users/cyanvoxel/Local/Dev/TagStudio/src/tagstudio/qt/controllers/search_panel_controller.py", line 126, in on_search_query_changed
    self.update_items(query)
  File "/Users/cyanvoxel/Local/Dev/TagStudio/src/tagstudio/qt/controllers/search_panel_controller.py", line 170, in update_items
    search_results: tuple[list[T], list[T]] = self.search_items(query_lower)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyanvoxel/Local/Dev/TagStudio/src/tagstudio/qt/controllers/tag_search_panel_controller.py", line 145, in search_items
    return self.__lib.search_tags(name=query, limit=self._get_limit()[1])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cyanvoxel/Local/Dev/TagStudio/src/tagstudio/core/library/alchemy/library.py", line 1316, in search_tags
    descendant_tags = [hierarchy.pop(id) for id in all_ids]
                       ^^^^^^^^^^^^^^^^^
KeyError: 1107

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority: CriticalAn issue that requires immediate attentionTagStudio: LibraryRelating to the TagStudio library systemTagStudio: TagsRelating to the TagStudio tag systemType: BugSomething isn't working as intended

    Type

    Fields

    No fields configured for Bug.

    Projects

    Status
    🛠 Ready for Development

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions