Fix: correct metadata update behavior (#11919)

### What problem does this PR solve?

Correct metadata update behavior. #11912

When update `value` is omitted, the corresponding keys are updated to
`"value"` regardless of their current values.

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Yongteng Lei
2025-12-12 12:50:17 +08:00
committed by GitHub
parent e37aea5f81
commit 6560388f2b

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