Re: [ovs-dev] [PATCH] python: Raise AttributeError from uuid_to_row
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 > --- > 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. ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
[ovs-dev] [PATCH] python: Raise AttributeError from uuid_to_row
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 --- python/ovs/db/idl.py | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 -- 2.35.1 ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Re: [ovs-dev] [PATCH] python: Raise AttributeError from uuid_to_row
On Sat, Apr 30, 2022 at 3:10 PM 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.) > Signed-off-by: Terry Wilson > --- > python/ovs/db/idl.py | 7 ++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py > index c98985773..ca61c5f73 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: Part of me thinks that we could just return atom here to return the UUID if the table wasn't registered, but I went with trying to restore the previous behavior. > +raise AttributeError( > +f"Table {base.ref_table.name} is not registered") from e > +return table.rows.get(atom) > else: > return atom > > -- > 2.35.1 > ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev
[ovs-dev] [PATCH] python: Raise AttributeError from uuid_to_row
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 --- python/ovs/db/idl.py | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py index c98985773..ca61c5f73 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: +raise AttributeError( +f"Table {base.ref_table.name} is not registered") from e +return table.rows.get(atom) else: return atom -- 2.35.1 ___ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev