fix(bib): upsert never blanks a stored value — empty incoming columns keep the stored ones (refs #615)

This commit is contained in:
kert
2026-09-08 12:42:30 -04:00
parent 961e294794
commit 5936cb8d42
2 changed files with 35 additions and 0 deletions

View File

@@ -283,6 +283,13 @@ class Store:
new_row = item.to_row() new_row = item.to_row()
cur_row = current.to_row() cur_row = current.to_row()
# Merge, don't replace: an empty incoming value carries no
# information (a list-walk row has no body), so the stored value
# wins. extra_json is always a full serialization and is exempt.
for c in self._COMPARE_COLS:
if c != "extra_json" and not new_row.get(c) and cur_row.get(c):
new_row[c] = cur_row[c]
setattr(item, c, cur_row[c])
same_cols = all( same_cols = all(
new_row.get(c, "") == cur_row.get(c, "") for c in self._COMPARE_COLS new_row.get(c, "") == cur_row.get(c, "") for c in self._COMPARE_COLS
) )

View File

@@ -74,3 +74,31 @@ def test_upsert_keeps_returning_key():
s = _store() s = _store()
key = s.upsert(_item()) key = s.upsert(_item())
assert s.upsert(_item()) == key assert s.upsert(_item()) == key
def test_empty_incoming_abstract_keeps_stored_body():
"""A list-walk row (no body) must not blank an enriched comment."""
s = _store()
key, _ = s.upsert_status(_item(abstract="enriched body"))
_, status = s.upsert_status(_item(abstract=""))
assert status == "unchanged"
assert s.get(key).abstract == "enriched body"
def test_empty_incoming_title_keeps_stored_title():
s = _store()
it = _item()
it.title = "Org: CMS-2026-2377-1"
key, _ = s.upsert_status(it)
it2 = _item()
it2.title = ""
_, status = s.upsert_status(it2)
assert status == "unchanged"
assert s.get(key).title == "Org: CMS-2026-2377-1"
def test_non_empty_incoming_still_updates():
s = _store()
key, _ = s.upsert_status(_item(abstract="v1"))
_, status = s.upsert_status(_item(abstract="v2"))
assert status == "updated" and s.get(key).abstract == "v2"