fix: a falsy upserted _id counts as a successful upsert

T2-14: update_document(upsert=True) and upsert_document_field returned
bool(matched_count or upserted_id), so an upsert that inserted _id 0, ""
or False reported failure. test matched_count > 0 or upserted_id is not None.

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
dsql committed 2026-10-16 04:12:27 -04:00
1 parent 0421fc734d
commit 4c7d5ff46d
1 file changed
+2 -2
+2 -2
View File
@@ -328,7 +328,7 @@ class MongoDB:
"""replace a whole document, optionally upserting"""
try:
response = await self._db[collection].replace_one(target, document, upsert=upsert)
return bool(response.matched_count or response.upserted_id)
return response.matched_count > 0 or response.upserted_id is not None
except Exception:
log.exception("db.update_document() on %s", collection)
return False
@@ -382,7 +382,7 @@ class MongoDB:
response = await self._db[collection].update_one(
target, {"$set": updates}, upsert=True
)
return bool(response.matched_count or response.upserted_id)
return response.matched_count > 0 or response.upserted_id is not None
except Exception:
log.exception("db.upsert_document_field() on %s", collection)
return False