Setting an XMP tag from a value with incorrect type results in a confusing KeyError being raised
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.
metadata.read()
metadata[
This fails with the following exception:
/home/osomon/
271 return getattr(self, '_set_%s_tag' % family)(key, tag_or_value)
272 except AttributeError:
--> 273 raise KeyError(key)
274
275 def _delete_
This is confusing to the user, because it seems to induce that the problem is with the key (Xmp.dc.
A correct assignment would be:
metadata[
Nevertheless, the exception raised in this case should be a TypeError, not a KeyError.
Changed in pyexiv2: | |
assignee: | nobody → Olivier Tilloy (osomon) |
status: | Confirmed → In Progress |
Changed in pyexiv2: | |
milestone: | none → 0.3.1 |
Changed in pyexiv2: | |
status: | Fix Committed → Fix Released |
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'