Fix: correct metadata update behavior

This commit is contained in:
yongtenglei 2025-12-12 10:09:50 +08:00
parent a6bd765a02
commit 1f9fdba8ec

View file

@ -761,13 +761,19 @@ class DocumentService(CommonService):
key = upd.get("key") key = upd.get("key")
if not key or key not in meta: if not key or key not in meta:
continue continue
new_value = upd.get("value") new_value = upd.get("value")
match_value = upd.get("match", new_value) match_provided = "match" in upd
if isinstance(meta[key], list): if isinstance(meta[key], list):
if not match_provided:
meta[key] = new_value
changed = True
else:
match_value = upd.get("match")
replaced = False replaced = False
new_list = [] new_list = []
for item in meta[key]: for item in meta[key]:
if match_value and _str_equal(item, match_value): if _str_equal(item, match_value):
new_list.append(new_value) new_list.append(new_value)
replaced = True replaced = True
else: else:
@ -776,8 +782,11 @@ class DocumentService(CommonService):
meta[key] = new_list meta[key] = new_list
changed = True changed = True
else: else:
if not match_value: if not match_provided:
continue meta[key] = new_value
changed = True
else:
match_value = upd.get("match")
if _str_equal(meta[key], match_value): if _str_equal(meta[key], match_value):
meta[key] = new_value meta[key] = new_value
changed = True changed = True