Timezone info is not correctly passed to libexiv2 when writing IPTC and XMP tags

Bug #797644 reported by Olivier Tilloy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyexiv2
Fix Released
Medium
Olivier Tilloy

Bug Description

(Originally reported by e-mail by Petri Damstén, thanks Petri!)

For datetime.tzinfo subclasses that are not pyexiv2.utils.FixedOffset, writing a datetime to a tag with a non-null timezone info will result in a wrongly formatted datetime, which cannot be read again subsequently. This affects IPTC tags as well as XMP tags. EXIF tags are not affected as timezone info is discarded (not handled in the specification).

Example script, with any image file (needs python-tz):

import pyexiv2
import pytz
from datetime import datetime

m=pyexiv2.ImageMetadata("image.jpg")
m.read()
m['Xmp.xmp.CreateDate'] = pytz.timezone("US/Eastern").localize(datetime.today())
m.write()
m=pyexiv2.ImageMetadata("image.jpg")
m.read()
print m['Xmp.xmp.CreateDate'].value

Expected result: prints the value of the tag with the correct timezone information.

Current result: "XmpValueError: Invalid value for XMP type [Date]: [2011-06-15T12:47:23.545156EDT]"

Tags: iptc xmp
Revision history for this message
Olivier Tilloy (osomon) wrote :

The root cause of the issue is the code that converts a datetime object to a string to be passed to libexiv2. It incorrectly assumes that if a timezone object is present, it must be an instance of pyexiv2.utils.FixedOffset, which is certainly not true when e.g. using pytz. The code should use "%z", not "%Z", to print out the timezone info.

Revision history for this message
Olivier Tilloy (osomon) wrote :

I’m attaching a patch originally proposed by Petri.
It will need a review, and probably updated unit tests.

Olivier Tilloy (osomon)
Changed in pyexiv2:
assignee: nobody → Olivier Tilloy (osomon)
status: Confirmed → In Progress
Revision history for this message
Olivier Tilloy (osomon) wrote :

Fixed with revision 359 in the trunk.

Thanks Petri for the original patch!

Changed in pyexiv2:
status: In Progress → Fix Committed
Olivier Tilloy (osomon)
Changed in pyexiv2:
milestone: none → 0.3.1
Olivier Tilloy (osomon)
Changed in pyexiv2:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.