Skip to content

Commit 0529925

Browse files
authored
fix: "Search for Tag" in Tag Manager executes multiple queries (#1173)
* test: add test to ensure actions are replaced when widgets are replaced * fix: disconnect previous action before adding new action
1 parent 5dcad41 commit 0529925

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/tagstudio/qt/mixed/tag_search.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def set_tag_widget(self, tag: Tag | None, index: int):
304304
tag_widget.on_edit.disconnect()
305305
tag_widget.on_remove.disconnect()
306306
tag_widget.bg_button.clicked.disconnect()
307+
tag_widget.search_for_tag_action.triggered.disconnect()
307308

308309
tag_id = tag.id
309310
tag_widget.on_edit.connect(lambda t=tag: self.edit_tag(t))

tests/qt/test_tag_search_panel.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Copyright (C) 2025
22
# Licensed under the GPL-3.0 License.
33
# Created for TagStudio: https://github.com/CyanVoxel/TagStudio
4-
5-
4+
from PySide6.QtCore import SIGNAL
65
from pytestqt.qtbot import QtBot
76

87
from tagstudio.core.library.alchemy.library import Library
98
from tagstudio.qt.mixed.tag_search import TagSearchPanel
9+
from tagstudio.qt.mixed.tag_widget import TagWidget
10+
from tagstudio.qt.ts_qt import QtDriver
1011

1112

1213
def test_update_tags(qtbot: QtBot, library: Library):
@@ -17,3 +18,35 @@ def test_update_tags(qtbot: QtBot, library: Library):
1718

1819
# When
1920
panel.update_tags()
21+
22+
23+
def test_tag_widget_actions_replaced_correctly(qtbot: QtBot, qt_driver: QtDriver, library: Library):
24+
panel = TagSearchPanel(library)
25+
qtbot.addWidget(panel)
26+
panel.driver = qt_driver
27+
28+
# Set the widget
29+
tags = library.tags
30+
panel.set_tag_widget(tags[0], 0)
31+
tag_widget: TagWidget = panel.scroll_layout.itemAt(0).widget()
32+
33+
should_replace_actions = {
34+
tag_widget: ["on_edit()", "on_remove()"],
35+
tag_widget.bg_button: ["clicked()"],
36+
tag_widget.search_for_tag_action: ["triggered()"],
37+
}
38+
39+
# Ensure each action has been set
40+
ensure_one_receiver_per_action(should_replace_actions)
41+
42+
# Set the widget again
43+
panel.set_tag_widget(tags[0], 0)
44+
45+
# Ensure each action has been replaced (amount of receivers is still 1)
46+
ensure_one_receiver_per_action(should_replace_actions)
47+
48+
49+
def ensure_one_receiver_per_action(should_replace_actions):
50+
for action, signal_strings in should_replace_actions.items():
51+
for signal_str in signal_strings:
52+
assert action.receivers(SIGNAL(signal_str)) == 1

0 commit comments

Comments
 (0)