Setting an XMP tag from a value with incorrect type results in a confusing KeyError being raised

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

Bug Description

(issue originally reported by Bob Swithers by e-mail)

Observed with pyexiv2 0.3.0, still valid in the latest trunk.
Steps to reproduce, on any image:

    import pyexiv2
    metadata = pyexiv2.ImageMetadata("test/data/smiley1.jpg")
    metadata.read()
    metadata['Xmp.dc.description'] = 'foo'

This fails with the following exception:

/home/osomon/dev/pyexiv2-branches/pyexiv2-0.3/src/pyexiv2/metadata.pyc in __setitem__(self, key, tag_or_value)
    271 return getattr(self, '_set_%s_tag' % family)(key, tag_or_value)
    272 except AttributeError:
--> 273 raise KeyError(key)
    274
    275 def _delete_exif_tag(self, key):

This is confusing to the user, because it seems to induce that the problem is with the key (Xmp.dc.description), which is perfectly valid, whereas the real issue is with the type of the tag (this particular one is of type LangAlt).

A correct assignment would be:

    metadata['Xmp.dc.description'] = {'x-default': 'foo'}

Nevertheless, the exception raised in this case should be a TypeError, not a KeyError.

Tags: xmp
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 at revision 361 of lp:~osomon/pyexiv2/pyexiv2-0.3.

Setting an XMP tag’s value to the wrong type will now raise a TypeError as expected.

On top of this, I made pyexiv2 more flexible; it will now accept a simple string for the value of a LangAlt tag and convert it automatically into a dictionary of the form {'x-default': value}. The following assignment will now work:

    metadata['Xmp.dc.description'] = 'foo'

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.