Bug 1388921 - Python API ovs.db.idl.Row.setkey does not work on new Rows
Summary: Python API ovs.db.idl.Row.setkey does not work on new Rows
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: openvswitch
Version: 7.1
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Open vSwitch development team
QA Contact: Network QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2016-10-26 13:09 UTC by Marcin Mirecki
Modified: 2016-11-08 17:06 UTC (History)
4 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-11-08 17:06:27 UTC
Target Upstream Version:


Attachments (Terms of Use)

Description Marcin Mirecki 2016-10-26 13:09:45 UTC
ovs.db.idl.Row.setkey does not work on newly created row.

Trying to execute code:

  transaction = ovs.db.idl.Transaction(self._ovsdb_connection)
  row = transaction.insert(self._ovsdb_connection.tables['<table name>'])
  row.setkey('<column>', '<key>', '<value>')

Will result in:

File "/usr/lib/python2.7/site-packages/ovs/db/idl.py", line 873, in setkey
    if column_name in self._data:
TypeError: argument of type 'NoneType' is not iterable

Comment 2 Aaron Conole 2016-10-26 18:43:43 UTC
Please write a more detailed issue.  The row in your code block doesn't exist yet (because the transaction wasn't committed), and I'm not sure if there exists a column with the name you've asked (because of the values in your example code).

Please post the minimum runnable version of code that fails.

Comment 3 Marcin Mirecki 2016-11-07 08:47:47 UTC
Does this not create a row:
row = transaction.insert(self._ovsdb_connection.tables['<table name>'])

If we have to commit the transaction before we add further fields, we end up with a partial transaction which is somewhat useless.


IMO it would not take much to extend the "setkey" method to cover this scenario as well. 
Currently you have to do this manually:

row = transaction.insert(self._ovsdb_connection.tables['<table name>'])
options = getattr(row, 'options', {})
options['key'] = 'value'

Not a lot of work, but since we have "setkey" I would expect to be able to use it here too.

Comment 4 Aaron Conole 2016-11-08 17:06:27 UTC
You don't have to commit the transaction before adding fields - but you do have to setup the keys before committing.  If you commit otherwise, it likely won't even be added to the database, because the schema validation would fail.

The architecture for this is quite complicated for very good reasons.  Please see the documentation in the IDL.py for some explanations on why we must set rows the way we do.

In the meantime, I'm closing this - it isn't a bug.


Note You need to log in before you can comment on or make changes to this bug.