diff mbox series

[ovs-dev] python: Raise AttributeError from uuid_to_row

Message ID 20220502133114.984166-1-twilson@redhat.com
State Accepted
Headers show
Series [ovs-dev] python: Raise AttributeError from uuid_to_row | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Terry Wilson May 2, 2022, 1:31 p.m. UTC
Prior to 4e3966e64, when calling _uuid_to_row, it would raise an
AttributeError when trying to access base.ref_table.rows if the
referenced table was not registered. When called from
Row.__getattr__(), this would appropriately raise an AttributeError.

After 4e3966e64, a KeyError would be raised, which is not expected
from a getattr() or hasattr() call, which could break existing
code.

Fixes: 4e3966e64 (python: Politely handle misuse of table.condition.)
Signed-off-by: Terry Wilson <twilson@redhat.com>
---
 python/ovs/db/idl.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Ilya Maximets May 2, 2022, 6:17 p.m. UTC | #1
On 5/2/22 15:31, Terry Wilson wrote:
> Prior to 4e3966e64, when calling _uuid_to_row, it would raise an
> AttributeError when trying to access base.ref_table.rows if the
> referenced table was not registered. When called from
> Row.__getattr__(), this would appropriately raise an AttributeError.
> 
> After 4e3966e64, a KeyError would be raised, which is not expected
> from a getattr() or hasattr() call, which could break existing
> code.
> 
> Fixes: 4e3966e64 (python: Politely handle misuse of table.condition.)

For the future: the length of the commit hash should be 12.

> Signed-off-by: Terry Wilson <twilson@redhat.com>
> ---
>  python/ovs/db/idl.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

Applied to master and branch-2.17.  Thanks!

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py
index c98985773..b87099ff5 100644
--- a/python/ovs/db/idl.py
+++ b/python/ovs/db/idl.py
@@ -1299,7 +1299,12 @@  class Row(object):
 
     def _uuid_to_row(self, atom, base):
         if base.ref_table:
-            return self._idl.tables[base.ref_table.name].rows.get(atom)
+            try:
+                table = self._idl.tables[base.ref_table.name]
+            except KeyError as e:
+                msg = "Table {} is not registered".format(base.ref_table.name)
+                raise AttributeError(msg) from e
+            return table.rows.get(atom)
         else:
             return atom