From b7d36aa9f54963fc1b65eca6d76e8669eb63a6e8 Mon Sep 17 00:00:00 2001 From: Mario Fetka Date: Thu, 23 Jul 2026 13:45:21 +0200 Subject: [PATCH] Treat missing Store documents as normal absence --- .../storetool/bongo/storetool/StoreCommands.py | 16 ++++++---------- src/apps/storetool/tests/test_python3_runtime.py | 5 +++++ src/libs/python/bongo/store/StoreClient.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/apps/storetool/bongo/storetool/StoreCommands.py b/src/apps/storetool/bongo/storetool/StoreCommands.py index 2a53d38..c2647f3 100644 --- a/src/apps/storetool/bongo/storetool/StoreCommands.py +++ b/src/apps/storetool/bongo/storetool/StoreCommands.py @@ -108,17 +108,13 @@ class DocumentPutCommand(Command): try: store.Store(options.store) - f = open(filename, "rb") - content = f.read() - try: - store.Info(document) - # Info throws an exception if the document doesn't exist + with open(filename, "rb") as source: + content = source.read() + if store.Info(document) is not None: store.Replace(document, content) - except: - # doesn't exist, so must write the new document - store.Write(doc_collection, doc_type, content, filename=doc_name) - - f.close() + else: + store.Write(doc_collection, doc_type, content, + filename=doc_name) except IOError as e: print(str(e)) diff --git a/src/apps/storetool/tests/test_python3_runtime.py b/src/apps/storetool/tests/test_python3_runtime.py index e4305cb..f897bc1 100644 --- a/src/apps/storetool/tests/test_python3_runtime.py +++ b/src/apps/storetool/tests/test_python3_runtime.py @@ -146,6 +146,11 @@ class Python3RuntimeTests(unittest.TestCase): self.assertTrue(client.stream.lines[2].endswith(" 7")) self.assertEqual(client.stream.raw, [expected, expected, expected]) + def test_store_info_treats_missing_document_as_normal_absence(self): + client = object.__new__(StoreClient) + client.stream = _Stream([_Response(4224, "Document doesn't exist")]) + self.assertIsNone(client.Info("/events/new-event")) + def test_calendar_share_token_uses_python3_hashlib(self): token = CalendarACL(None)._GetUid("calendar") self.assertEqual(len(token), 32) diff --git a/src/libs/python/bongo/store/StoreClient.py b/src/libs/python/bongo/store/StoreClient.py index 3e59fbe..28a5d76 100644 --- a/src/libs/python/bongo/store/StoreClient.py +++ b/src/libs/python/bongo/store/StoreClient.py @@ -567,7 +567,7 @@ class StoreClient: # eat the response line self.stream.GetResponse() return item - elif r.code == 1000: + elif r.code in (1000, 4224): return None raise CommandError(r)