]> git.proxmox.com Git - mirror_ovs.git/commitdiff
python: KeyError shouldn't be raised from __getattr__
authorTimothy Redaelli <tredaelli@redhat.com>
Mon, 12 Mar 2018 10:52:21 +0000 (11:52 +0100)
committerRussell Bryant <russell@ovn.org>
Wed, 14 Mar 2018 15:34:05 +0000 (11:34 -0400)
On Python 3 hasattr only intercepts AttributeError exception.
On Python2, instead, hasattr intercepts all the exceptions.

This means __getattr__ shouldn't return KeyError when the attribute
doesn't exists, but it should raise AttributeError instead.

Fixes: 2d54d8011e14 ("Python-IDL: getattr after mutate fix")
Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
Signed-off-by: Russell Bryant <russell@ovn.org>
python/ovs/db/idl.py

index 5a4d129c0e13ff0e0f99241e02df49f8bd4f4e43..773a604edcf7320da5eca5fe37282ac50a36cc69 100644 (file)
@@ -774,7 +774,11 @@ class Row(object):
         assert self._changes is not None
         assert self._mutations is not None
 
-        column = self._table.columns[column_name]
+        try:
+            column = self._table.columns[column_name]
+        except KeyError:
+            raise AttributeError("%s instance has no attribute '%s'" %
+                                 (self.__class__.__name__, column_name))
         datum = self._changes.get(column_name)
         inserts = None
         if '_inserts' in self._mutations.keys():