Bug 434795 - Advanced search seems to notice internal tags
Summary: Advanced search seems to notice internal tags
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Searches-Advanced (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-22 21:10 UTC by Matti Klock
Modified: 2021-03-24 06:57 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 7.3.0
Sentry Crash Report:


Attachments
search that by definition should return no photos but actually returns all my untagged photos (66.71 KB, image/png)
2021-03-22 21:10 UTC, Matti Klock
Details
no tags selected but 19 tags are selected (42.25 KB, image/png)
2021-03-23 01:39 UTC, Matti Klock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matti Klock 2021-03-22 21:10:58 UTC
Created attachment 136955 [details]
search that by definition should return no photos but actually returns all my untagged photos

SUMMARY
Advanced Search -> "Return items with tag" dropdown can be made to select and search by tags that are not actually visible in the dropdown.

STEPS TO REPRODUCE
1. Create a new Advanced Search. Leave it as "Meet All of the following conditions".
2. Under "Tags", click "Not Tagged".
3. Under "Tags", go to the "Return items with tag" dropdown. Right-click to get the context menu, then click Select -> All Tags.
  b. Then *manually* deselect all the tags in the dropdown.
4. Search.

OBSERVED RESULT

The search returns all of my untagged photos.

When I close the dropdown, it says "22 Tags selected". There's no evidence of what these tags are, and re-opening the dropdown shows all my tags deselected.

Clicking search then returns all untagged photos.

If I uncheck "Not Tagged" and try again, I get almost all of my photos -- everything except videos and some screencaps. That makes me think the 22 mystery tags are real tags that are used internally. 

EXPECTED RESULT

The search should return 0 photos, since the two clauses are contradictory.

"Return items with tag" will say "0 tags selected". If it DOES show that some tags are selected, then the search should return 0 items, since "Not Tagged" is also checked off.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Kubuntu 20.04
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8

ADDITIONAL INFORMATION

When I go back into the "Return items with tags" dropdown and *manually* deselect everything in the list, the dropdown still says "22 Tags selected", and the search still returns all my non-tagged photos. This makes me think that there are 22 real tags that are used internally, and Advanced Search is accidentally selecting them.  

The reason this matters at all:

I was trying to search for photos that have zero of my non-People tags. There seemed to be an easy way to construct the negative clause I needed: select the People tree, then click Invert Selection. But this then encompassed the 22 mystery tags that don't belong to me and are on all of my photos, which in turn led to the wrong search behavior.

I worked around this by just clicking all my non-People tags manually. It's a pain, but totally doable.
Comment 1 Maik Qualmann 2021-03-22 21:34:02 UTC
With 243 selected individual tags, they exceed the maximum length of a SQLite query. We already know the problem. One possible solution would be to use MySQL. Another solution is hardly possible with SQLite, for example splitting the query.

Maik
Comment 2 Maik Qualmann 2021-03-22 21:39:05 UTC
Although the maximum number of 999 parameters has not yet been reached. Are you using MySQL or SQLite?

I cannot reproduce a problem here with digiKam-7.2.0 and MySQL.

Maik
Comment 3 Maik Qualmann 2021-03-22 21:44:07 UTC
Which digiKam version are you using exactly? The story that the tag selector shows after clearing 22 tags cannot be explained or reproduced at all.

Maik
Comment 4 Matti Klock 2021-03-23 01:39:08 UTC
Created attachment 136962 [details]
no tags selected but 19 tags are selected
Comment 5 Matti Klock 2021-03-23 01:44:20 UTC
Wow, thank you for the fast response!

I managed to butcher part of my bug report while editing it. "OBSERVED RESULTS" should say simply "the search returns all of my untagged photos". (I think you read it correctly despite this.)


Yes, I'm using SQLite. I normally use Digikam 6.4. I just tried the 7.2.0-rc appimage and got the same result.

Then I tried 7.2.0-rc on a fresh database and a root folder with a few images. I was able to get the Advanced Search selector to claim it had selected 19 invisible tags (see new screenshot). I couldn't get it to return any photos with that search until I tried to run face detection; then it returned one photo.

Poking around with sqlitebrowser showed that the Tags table starts with ~20 tags that look internal ("Color Label Red", "Scanned for Faces"), and that they do get linked to images via ImageTags.
Comment 6 Maik Qualmann 2021-03-23 07:41:15 UTC
Can you also test it with a new digikamrc configuration file?

If you press the reset button of the advanced search, the display does not go back to "All tags"?

I cannot reproduce the problem here at the moment. Such a problem would certainly have been noticed several times, but has not yet been reported. I see in the code that we are not putting an object name on this tag selection combo box. I could imagine that the automatic loading state is the cause here.

Maik
Comment 7 Matti Klock 2021-03-23 13:16:58 UTC
Yes -- I tried with a separate user account, so the digikamrc was brand new.

And yes, when I press the reset button, the dropdown goes back to "Any tag". That works fine.

This bug is only really a problem for the type of search I was trying to do: finding all photos that had no tags outside of a certain subtree. I'll try to upload an animated GIF later today showing what I did. But this bug is absolutely not a release blocker or anything like that.
Comment 8 Maik Qualmann 2021-03-23 22:17:34 UTC
Git commit 63b512754ab78e56f10563de3c78c8f73e99d4e1 by Maik Qualmann.
Committed on 23/03/2021 at 22:15.
Pushed by mqualmann into branch 'master'.

filter out internal tags when selecting all or inverting the selection
FIXED-IN: 7.3.0

M  +2    -1    NEWS
M  +19   -0    core/libs/models/abstractalbummodel.cpp

https://invent.kde.org/graphics/digikam/commit/63b512754ab78e56f10563de3c78c8f73e99d4e1
Comment 9 Maik Qualmann 2021-03-24 06:57:42 UTC
Git commit 37e96c116b90119c8c116440159d69dee7aa2be3 by Maik Qualmann.
Committed on 24/03/2021 at 06:56.
Pushed by mqualmann into branch 'master'.

move the code to the TagModel

M  +0    -22   core/libs/models/abstractalbummodel.cpp
M  +12   -0    core/libs/models/albummodel.cpp
M  +3    -0    core/libs/models/albummodel.h

https://invent.kde.org/graphics/digikam/commit/37e96c116b90119c8c116440159d69dee7aa2be3