Bug 472914

Summary: Face tag subfolders get converted to backslash instead of forward slash when metadata reread
Product: [Applications] digikam Reporter: deryk.lister
Component: Metadata-XmpAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: metzpinguin
Priority: NOR    
Version First Reported In: 8.1.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In: 8.2.0
Sentry Crash Report:

Description deryk.lister 2023-08-02 08:13:16 UTC
SUMMARY
Say your tag structure for faces has subfolders, which appear correctly in the tag hierarchy in the tags tab e.g.:
People/Famous/King Charles
People/Staff/Fred Smith
People/Staff/Joe Bloggs
If face tagging is used, when metadata is written to the file and re-read again duplicate tags are created so your tag list becomes:
People/Famous/King Charles
People/Famous\King  Charles
People/Staff/Fred Smith
People/Staff\Fred Smith
People/Staff/Joe Bloggs
People/Staff\Joe Bloggs
The backslash version of the tag is applied to the face region and both tags are applied to the image metadata.

STEPS TO REPRODUCE
1. Use face tagging on a region of a photo and where it says "Who is this?" put in Famous/King Charles  (doesn't need the "People/" prefix as face tags all go under "People" by default) 
2. If the person tag doesn't exist yet, click on "Create "Famous/King Charles" in People" to create it
3. Check the image tags (an easy way is right click - hover over "Remove tag"), there should only be one, for "People / Famous / King Charles"
4. Item menu - write metadata to file
5. Item menu - reread metadata from file
6. Check the image tags again

OBSERVED RESULT
There are now two image tags listed when checking (step 3) - "People / Famous / King Charles" and "People / Famous\King Charles"  (if using the "Remove tag" menu to check, the latter is displayed indented as "   Famous\King Charles").  In the Tags tab, you can see that as well as a hierarchy of People|Famous|King Charles there is also a duplicate People|Famous\King Charles (displayed in the UI with the backslash).  The face tagging on the image will use the latter.

EXPECTED RESULT
No change after rereading metadata from file - there should only be People|Famous|King Charles in the tags hierarchy, and not a People|Famous\King Charles.

SOFTWARE/OS VERSIONS
Windows: Windows 11 22H2

ADDITIONAL INFORMATION
I suspect this is specific to Windows, seeing as the filesystem uses backslashes.  My guess is that there's an extra conversion happening that shouldn't be.
This only affects face tagging - if you don't tag any regions of the image as a face and just use normal tagging, hierarchies behave as normal.
Comment 1 deryk.lister 2023-08-02 08:35:07 UTC
Tested latest weekly 8.2.0 build, same result
Comment 2 Maik Qualmann 2023-08-02 08:37:44 UTC
This is not a bug, you can only enter names when assigning faces, not names with a path. "The entry "Famous/King Charles" is seen as a full name, in this case, since the slash is not allowed in names, we convert it to a backslash.

Even if we manage names in a hierarchy in the People Tags Tree , this cannot be represented in metadata, it is a flat list of names.

Maik
Comment 3 Maik Qualmann 2023-08-02 08:39:55 UTC
As a fix, we will disallow the slash when entering people names.

Maik
Comment 4 deryk.lister 2023-08-02 08:43:26 UTC
That seems odd as the name works perfectly with a path internally and treats it, as expected, as a path inside "People" so that you can organise your people into groups.  It's only when writing metadata to file and re-reading it again that your arbitrary rule seems to enforce itself and create a duplicate tag.
Comment 5 Maik Qualmann 2023-08-02 08:50:31 UTC
Yes, we will fix it, we don't store the last part of the name in the face metadata.

Maik
Comment 6 Maik Qualmann 2023-08-02 11:03:03 UTC
A corresponding patch is in the works. But, don't create another face name like this with a slash. You must delete all face names created in this way. Even if it looks correct in the tags tree, a single name is created with slash. It's amazing that nobody has triggered this problem in years.

Maik
Comment 7 deryk.lister 2023-08-02 13:14:14 UTC
Thanks for the update.  I think I understand now!  From an end user perspective my main concern was just the end result: whether I was stuck trying to tag a few hundred people but have them all listed in one lump rather than be able to group them into "Staff", "Public Figure", etc.  Having no structure to them would be a nightmare.  As we're looking at it from different perspectives, your comment from your perspective of "that's not a bug" worried me that I was stuck having to completely rethink the structure.

As it turns out, it seems what I want *is* achievable, I've just been creating the "Parent" tags (folders, so to speak) in an unexpected way that put a face tag of say "Famous\King Charles" into the database whilst the tag side of things sorted itself out and hid the problem.  I uncovered the symptoms when wanting to copy face tags from one photo to another and hearing it was only possible via exiftool and doing that (so copying the metadata from photo A to photo B then loading it with the reload from file menu).

To me my attempted usage makes sense, as it's how it can work throughout the UI - when creating a new tag directly on an image, the UI invites you to create a tags hierarchy like "Country/City/Paris" by typing it that way and it creates the whole structure if it's missing (sort of like a mkdir -p).  So this is how I created my first staff tag - I typed in "Staff/Fred Smith" into the face tagging UI which "works" superficially (but breaks things underneath).

When I was experimenting just now and pre-created my structure (including names) in Tag Manager first then just *selected* them when face tagging, I'm finding it works fine and still keeps the grouping.  But selecting names that existed from when I did it "wrong", even without typing any slashes into the face tagging UI, pulls the incorrect backslashed-form from the backend somewhere.

I have a lot of broken face tags in this way at the moment but it seems I have a workaround to fix them:
1. In the People UI, rename say "King Charles" to "King Charles II".  In the metadata, "Region Name" and "Region Person Display Name" change from "Famous\King Charles" to "King Charles II".
2. Rename him back to "King Charles".   In the metadata, "Region Name" and "Region Person Display Name" change from "King Charles II" to "King Charles" (so it's now corrected)

So it looks like I can repair them all "fairly easily" by renaming them in the People UI and just adding a 1 on the end or something and then renaming them all back again, whilst retaining the hierarchical tag structure I wanted.

The obvious flaw here in face data being flat whilst the associated tags can be hierarchical, is when you have a John Smith under "Famous" and a different John Smith under "Staff", it's the same name so seen as the same person.  Luckily not a scenario I've had to deal with yet.
Comment 8 Maik Qualmann 2023-08-02 20:43:55 UTC
Git commit d4fa68a90e090d434ea33fe2b0c5889d6f68366c by Maik Qualmann.
Committed on 02/08/2023 at 22:42.
Pushed by mqualmann into branch 'master'.

allow to create face tags by path
FIXED-IN: 8.2.0

M  +1    -1    NEWS
M  +11   -1    core/app/items/overlays/assignnameoverlay.cpp
M  +3    -9    core/libs/database/tags/facetags.cpp
M  +11   -1    core/utilities/facemanagement/items/facegroup.cpp

https://invent.kde.org/graphics/digikam/-/commit/d4fa68a90e090d434ea33fe2b0c5889d6f68366c