Bug 449754

Summary: Empty metadata XMP values are created when applying template
Product: [Applications] digikam Reporter: José Oliver-Didier <jose_oliver>
Component: Metadata-TemplateAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: metzpinguin
Priority: NOR    
Version: 7.5.0   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In: 8.0.0
Sentry Crash Report:
Attachments: Exiftool panel with empty fields screenshot
DebugView Log
Geosetter - Assign values from Template

Description José Oliver-Didier 2022-02-07 17:58:36 UTC
Created attachment 146398 [details]
Exiftool panel with empty fields screenshot

SUMMARY
Empty metadata XMP values are created when applying template


STEPS TO REPRODUCE
1. Select an image and click on "Captions" on the right sidebar.
2. Create a new Metadata Template with Sublocation, City, Province-State, Country Information.
3. Apply Metadata Template to Image and have it saved to file.
4. Select "Metadata" from right sidebar and click on "Exiftool"

OBSERVED RESULT
- Empty Metadata fields (see attached screenshot)

EXPECTED RESULT
- Metadata fields with no values should not be added to file XMP.
- If a value is empty the XMP entry should not be added.

SOFTWARE/OS VERSIONS
Windows 11

ADDITIONAL INFORMATION
- Inconsistent with other metadata template application in Digikam - Did not see this occur with template with Copyright.
- Running command to extract XMP:   exiftool <filename> -xmp -b > output.txt 

Example:
			<Iptc4xmpCore:CreatorContactInfo Iptc4xmpCore:CiAdrCity=""
			                                 Iptc4xmpCore:CiAdrCtry=""
			                                 Iptc4xmpCore:CiAdrExtadr=""
			                                 Iptc4xmpCore:CiAdrPcode=""
			                                 Iptc4xmpCore:CiAdrRegion=""
			                                 Iptc4xmpCore:CiEmailWork=""
			                                 Iptc4xmpCore:CiTelWork=""
			                                 Iptc4xmpCore:CiUrlWork=""/>
Comment 1 José Oliver-Didier 2022-02-07 18:01:08 UTC
Sounds related to the issue in Bug 231114
Comment 2 Maik Qualmann 2022-02-07 18:40:50 UTC
I can't reproduce the problem, all contact info is also written in XMP. DebugView and see if there are any problems writing the metadata.

Maik
Comment 3 Maik Qualmann 2022-02-07 18:46:03 UTC
Here is the code, all possible XMP fields are written:

https://invent.kde.org/graphics/digikam/-/blob/master/core/libs/metadataengine/dmetadata/dmetadata_iptc.cpp#L77

Maik
Comment 4 José Oliver-Didier 2022-02-07 21:46:29 UTC
Created attachment 146406 [details]
DebugView Log

Attaching DebugView log snipplet. From line 98 you can observe that the empty fields are being written to. I did not specify any values to those fields. Could it be a Windows only issue in which an empty field is misinterpreted as containing a value?
Comment 5 Maik Qualmann 2022-02-07 21:54:38 UTC
The template overwrites all fields. That empty fields should be skipped has already been requested in other bug reports. But what is the best way to do it if deletion is desired?

Maik
Comment 6 José Oliver-Didier 2022-02-07 23:09:57 UTC
Created attachment 146412 [details]
Geosetter - Assign values from Template

- If deletion is desired it should remove the xmp value and tag/attribute altogether, not leave the tag/attribute with an empty value.
- For the application part, I am attaching a screenshot of the dialog window Geosetter brings up when you apply a custom template. It prompts the user to check/uncheck to which of the fields in the template to apply its values, otherwise they are ignored.
Comment 7 Maik Qualmann 2022-12-06 18:12:38 UTC
Git commit d672e63c7174e09935b27bcdd55e3d5fb1627791 by Maik Qualmann.
Committed on 06/12/2022 at 18:11.
Pushed by mqualmann into branch 'master'.

change template behavior to merge the metadata
- empty template fields no longer overwrite metadata
- fix removing template when using sidebar
- no empty metadata is written.
Related: bug 231114

M  +2    -2    NEWS
M  +4    -7    core/dplugins/bqm/metadata/assigntemplate/assigntemplate.cpp
M  +2    -14   core/libs/fileactionmanager/metadatahub.cpp
M  +71   -0    core/libs/metadataengine/containers/metadatainfo.cpp
M  +2    -0    core/libs/metadataengine/containers/metadatainfo.h
M  +48   -0    core/libs/metadataengine/containers/template.cpp
M  +5    -0    core/libs/metadataengine/containers/template.h
M  +90   -36   core/libs/metadataengine/dmetadata/dmetadata_iptc.cpp
M  +102  -57   core/libs/metadataengine/dmetadata/dmetadata_template.cpp
M  +3    -8    core/libs/properties/captions/disjointmetadata.cpp
M  +19   -2    core/libs/properties/captions/itemdescedittab_infoview.cpp
M  +8    -8    core/utilities/import/backend/cameracontroller.cpp

https://invent.kde.org/graphics/digikam/commit/d672e63c7174e09935b27bcdd55e3d5fb1627791