From 4c7d5ff46dca4bae8f8d63aa533b95aea35f1bbd Mon Sep 17 00:00:00 2001 From: disqualifier Date: Fri, 16 Oct 2026 04:12:27 -0400 Subject: [PATCH] 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 --- src/mongo/mongo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mongo/mongo.py b/src/mongo/mongo.py index 0ad458d..a980bf1 100644 --- a/src/mongo/mongo.py +++ b/src/mongo/mongo.py @@ -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