writing iptc field raises exception oldValues has no len() and/or newValues not iterable

Bug #343403 reported by Matthias Flege
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pyexiv2
Fix Released
High
Olivier Tilloy

Bug Description

steps to reproduce:

>>> import pyexiv2
>>> import datetime
>>> image = pyexiv2.Image('sample.jpg')
>>> image.readMetadata()
>>> d = datetime.date(2009, 03, 16)
>>> image['Iptc.Application2.DateCreated'] = d
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/pyexiv2.py", line 648, in __setitem__
    for i in xrange(max(len(oldValues), len(newValues))):
TypeError: object of type 'datetime.date' has no len()
>>>
>>> # deleting the field first, is a possible workaround
... # but triggers another bug
... del(image['Iptc.Application2.DateCreated'])
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/lib/python2.5/site-packages/pyexiv2.py", line 690, in __delitem__
    for i in xrange(len(oldValues)):
TypeError: object of type 'datetime.date' has no len()
>>> image['Iptc.Application2.DateCreated'] = d
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/pyexiv2.py", line 659, in __setitem__
    self.__iptcTagsDict[key] = tuple([ConvertToPythonType(tagFamily, typeName, str(v)) for v in newValues])
TypeError: 'datetime.date' object is not iterable

Patch against 0.1.2 attached.
Feel free to modify it, it's rather crude.

Revision history for this message
Matthias Flege (m-flege) wrote :
Revision history for this message
Matthias Flege (m-flege) wrote :

oops, was too fast. The del(...) already produces an exception.
The new patch fixes that also.

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

Note that this happens regardless of whether the tag (here 'Iptc.Application2.DateCreated') has been read before trying to set it.

Changed in pyexiv2:
importance: Undecided → High
milestone: none → 0.2
status: New → Confirmed
Revision history for this message
Olivier Tilloy (osomon) wrote :

Fixed in the 0.2 branch. Note that IPTC tags now consistently handle their values, always expecting a list or tuple. They will not try to wrap a single value into a list (that would raise a TypeError).

The expected syntax for the original example would now look like this:

    import pyexiv2, datetime
    metadata = pyexiv2.ImageMetadata('sample.jpg')
    metadata.read()
    key = 'Iptc.Application2.DateCreated'
    values = [datetime.date.today()]
    if key in metadata.iptc_keys:
        metadata[key].values = values
    else:
        metadata[key] = pyexiv2.IptcTag(key, values)

Changed in pyexiv2:
status: Confirmed → Fix Committed
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.