mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 06:15:47 +00:00
Python-IDL: getattr after mutate fix
This commit returns the updated column value when getattr is done
after a mutate operation is performed (but before the commit).
Signed-off-by: Amitabha Biswas <azbiswas@gmail.com>
Reported-by: Richard Theis <rtheis@us.ibm.com>
Reported-at: http://openvswitch.org/pipermail/dev/2016-September/080120.html
Fixes: a59912a0ee
("python: Add support for partial map and set updates")
Signed-off-by: Russell Bryant <russell@ovn.org>
This commit is contained in:
committed by
Russell Bryant
parent
36af136b69
commit
2d54d8011e
@@ -770,6 +770,7 @@ class Row(object):
|
||||
assert self._changes is not None
|
||||
assert self._mutations is not None
|
||||
|
||||
column = self._table.columns[column_name]
|
||||
datum = self._changes.get(column_name)
|
||||
inserts = None
|
||||
if '_inserts' in self._mutations.keys():
|
||||
@@ -784,24 +785,33 @@ class Row(object):
|
||||
(self.__class__.__name__,
|
||||
column_name))
|
||||
else:
|
||||
datum = inserts
|
||||
if column_name in self._data:
|
||||
datum = data.Datum.from_python(column.type,
|
||||
inserts,
|
||||
_row_to_uuid)
|
||||
elif column_name in self._data:
|
||||
datum = self._data[column_name]
|
||||
try:
|
||||
if column.type.is_set():
|
||||
dlist = datum.as_list()
|
||||
if inserts is not None:
|
||||
datum.extend(inserts)
|
||||
dlist.extend(list(inserts))
|
||||
if removes is not None:
|
||||
datum = [x for x in datum if x not in removes]
|
||||
except error.Error:
|
||||
pass
|
||||
try:
|
||||
removes_datum = data.Datum.from_python(column.type,
|
||||
removes,
|
||||
_row_to_uuid)
|
||||
removes_list = removes_datum.as_list()
|
||||
dlist = [x for x in dlist if x not in removes_list]
|
||||
datum = data.Datum.from_python(column.type, dlist,
|
||||
_row_to_uuid)
|
||||
elif column.type.is_map():
|
||||
dmap = datum.to_python(_uuid_to_row)
|
||||
if inserts is not None:
|
||||
datum.merge(inserts)
|
||||
dmap.update(inserts)
|
||||
if removes is not None:
|
||||
for key in removes.keys():
|
||||
del datum[key]
|
||||
except error.Error:
|
||||
pass
|
||||
for key in removes:
|
||||
if key not in (inserts or {}):
|
||||
del dmap[key]
|
||||
datum = data.Datum.from_python(column.type, dmap,
|
||||
_row_to_uuid)
|
||||
else:
|
||||
if inserts is None:
|
||||
raise AttributeError("%s instance has no attribute '%s'" %
|
||||
@@ -870,7 +880,7 @@ class Row(object):
|
||||
vlog.err("attempting to write bad value to column %s (%s)"
|
||||
% (column_name, e))
|
||||
return
|
||||
if column_name in self._data:
|
||||
if self._data and column_name in self._data:
|
||||
# Remove existing key/value before updating.
|
||||
removes = self._mutations.setdefault('_removes', {})
|
||||
column_value = removes.setdefault(column_name, set())
|
||||
|
Reference in New Issue
Block a user