Patches 1/5, 2/5, 5/5 look fine to me. On Sep 11, 2555 BE, at 23:17, Isaku Yamahata <[email protected]> wrote:
> In some cases getattr(Row instance, attrname) doesn't raise AttributeError, > but TypeError > >> File "python/ovs/db/idl.py", line 554, in __getattr__ >> datum = self._data[column_name] >> TypeError: 'NoneType' object has no attribute '__getitem__' > > So getattr(Row instance, attrname, default value) doesn't work. > This occurs when row._changes doesn't include attrname and row._data is None. > So teach Row.__getattr__ _data=None case. > > Signed-off-by: Isaku Yamahata <[email protected]> > --- > python/ovs/db/idl.py | 3 +++ > tests/ovsdb-idl.at | 9 +++++++++ > tests/test-ovsdb.py | 8 ++++++++ > 3 files changed, 20 insertions(+), 0 deletions(-) > > diff --git a/python/ovs/db/idl.py b/python/ovs/db/idl.py > index 249fbaf..7dc480f 100644 > --- a/python/ovs/db/idl.py > +++ b/python/ovs/db/idl.py > @@ -548,6 +548,9 @@ class Row(object): > > datum = self._changes.get(column_name) > if datum is None: > + if self._data is None: > + raise AttributeError("%s instance has no attribute '%s'" % > + (self.__class__.__name__, column_name)) > datum = self._data[column_name] > > return datum.to_python(_uuid_to_row) > diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at > index 68fe868..f4ed27e 100644 > --- a/tests/ovsdb-idl.at > +++ b/tests/ovsdb-idl.at > @@ -439,3 +439,12 @@ OVSDB_CHECK_IDL_PY([external-linking idl, insert ops], > 002: i=2 k=1 ka=[1 2] l2= uuid=<1> > 003: done > ]]) > + > +OVSDB_CHECK_IDL_PY([getattr idl, insert ops], > + [], > + [['getattrtest']], > + [[000: empty > +001: commit, status=success > +002: i=2 k=2 ka=[] l2= uuid=<0> > +003: done > +]]) > diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py > index 170476d..392ed4b 100644 > --- a/tests/test-ovsdb.py > +++ b/tests/test-ovsdb.py > @@ -321,6 +321,14 @@ def idl_set(idl, commands, step): > l1_1.i = 2 > l1_1.k = [l1_0] > l1_1.ka = [l1_0, l1_1] > + elif name == 'getattrtest': > + l1 = txn.insert(idl.tables["link1"]) > + i = getattr(l1, 'i', 1) > + assert i == 1 > + l1.i = 2 > + i = getattr(l1, 'i', 1) > + assert i == 2 > + l1.k = [l1] > else: > sys.stderr.write("unknown command %s\n" % name) > sys.exit(1) > -- > 1.7.1.1 > > _______________________________________________ > dev mailing list > [email protected] > http://openvswitch.org/mailman/listinfo/dev _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
