fix(api): delete item for multi-value attributes

This commit is contained in:
pycook 2024-07-30 20:05:21 +08:00
parent 68b7497bba
commit 542a876ead
1 changed files with 5 additions and 2 deletions

View File

@ -237,6 +237,9 @@ class AttributeValueManager(object):
if attr.is_list: if attr.is_list:
if isinstance(value, dict): if isinstance(value, dict):
if value.get('op') == "delete": if value.get('op') == "delete":
value['v'] = [ValueTypeMap.serialize[attr.value_type](
self._deserialize_value(attr.alias, attr.value_type, i))
for i in handle_arg_list(value['v'])]
continue continue
_value = value.get('v') or [] _value = value.get('v') or []
else: else:
@ -295,9 +298,9 @@ class AttributeValueManager(object):
has_dynamic = True has_dynamic = True
elif value.get('op') == "delete": elif value.get('op') == "delete":
for idx, v in enumerate((value.get('v') or [])): for v in (value.get('v') or []):
if v in existed_values: if v in existed_values:
existed_values[idx].delete(flush=False, commit=False) existed_attrs[existed_values.index(v)].delete(flush=False, commit=False)
if not attr.is_dynamic: if not attr.is_dynamic:
changed.append((ci.id, attr.id, OperateType.DELETE, v, None, ci.type_id)) changed.append((ci.id, attr.id, OperateType.DELETE, v, None, ci.type_id))
else: else: