From 91aca4ca1b0212b211b669895cb2b41fc71e3ee1 Mon Sep 17 00:00:00 2001 From: Mark Kasaboski Date: Tue, 26 Nov 2024 10:27:53 -0500 Subject: [PATCH] Fixes potential non-existent attribute error in save_collection_value() --- packages/flare/bin/cron_job_ingest_events.py | 23 +++++++++++--------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/flare/bin/cron_job_ingest_events.py b/packages/flare/bin/cron_job_ingest_events.py index 6865384..036f7a7 100644 --- a/packages/flare/bin/cron_job_ingest_events.py +++ b/packages/flare/bin/cron_job_ingest_events.py @@ -246,11 +246,13 @@ def save_last_fetched(kvstore: KVStoreCollections) -> None: def get_collection_value(kvstore: KVStoreCollections, key: str) -> Optional[str]: - if KV_COLLECTION_NAME in kvstore: - data = kvstore[KV_COLLECTION_NAME].data.query() - for entry in data: - if entry["_key"] == key: - return entry["value"] + # Ensure collection exists + create_collection(kvstore=kvstore) + + data = kvstore[KV_COLLECTION_NAME].data.query() + for entry in data: + if entry["_key"] == key: + return entry["value"] return None @@ -265,11 +267,12 @@ def save_collection_value(kvstore: KVStoreCollections, key: str, value: Any) -> } ) ) - else: - kvstore[KV_COLLECTION_NAME].data.update( - id=key, - data=json.dumps({"value": value}), - ) + return + + kvstore[KV_COLLECTION_NAME].data.update( + id=key, + data=json.dumps({"value": value}), + ) def fetch_feed(