From 24f11cabde7d71b24a1f84c8e0f058e62232c81a Mon Sep 17 00:00:00 2001 From: Paul Tikken Date: Wed, 26 Jun 2024 12:08:12 +0000 Subject: [PATCH] possible fix for cve-search/cve-search#1103 --- CveXplore/core/database_actions/db_action.py | 7 +++++-- CveXplore/core/database_maintenance/sources_process.py | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CveXplore/core/database_actions/db_action.py b/CveXplore/core/database_actions/db_action.py index 19101da8..e8984cdc 100644 --- a/CveXplore/core/database_actions/db_action.py +++ b/CveXplore/core/database_actions/db_action.py @@ -13,7 +13,7 @@ class DatabaseAction(object): actions = collections.namedtuple("Actions", "InsertOne UpdateOne")(0, 1) - def __init__(self, action: actions, doc: dict): + def __init__(self, action: actions, doc: dict, upsert: bool = True): """ Create a DatabaseAction object. @@ -23,6 +23,7 @@ def __init__(self, action: actions, doc: dict): """ self.action = action self.doc = doc + self.upsert = upsert @property def entry(self): @@ -37,4 +38,6 @@ def entry(self): if self.action == self.actions.InsertOne: return InsertOne(self.doc) elif self.action == self.actions.UpdateOne: - return UpdateOne({"id": self.doc["id"]}, {"$set": self.doc}, upsert=True) + return UpdateOne( + {"id": self.doc["id"]}, {"$set": self.doc}, upsert=self.upsert + ) diff --git a/CveXplore/core/database_maintenance/sources_process.py b/CveXplore/core/database_maintenance/sources_process.py index ed5468fb..f1d0eca5 100644 --- a/CveXplore/core/database_maintenance/sources_process.py +++ b/CveXplore/core/database_maintenance/sources_process.py @@ -1048,8 +1048,7 @@ def process_item(self, item): if epss is not None: self.queue.put( DatabaseAction( - action=DatabaseAction.actions.UpdateOne, - doc=epss, + action=DatabaseAction.actions.UpdateOne, doc=epss, upsert=False ) )