From 06c40475e3b9030d7d26e9060bb259f1969346a7 Mon Sep 17 00:00:00 2001 From: PT <11720165+P-T-I@users.noreply.github.com> Date: Fri, 28 Jun 2024 07:00:50 +0200 Subject: [PATCH] epss fix (#292) * fix for cve-search/cve-search#1103 on re-import * fix for cve-search/cve-search#1099 --- CveXplore/.schema_version | 2 +- CveXplore/core/database_actions/db_action.py | 7 +++++-- CveXplore/core/database_maintenance/sources_process.py | 3 +-- requirements/modules/mongodb.txt | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CveXplore/.schema_version b/CveXplore/.schema_version index d38695d7e..0f1efb3aa 100644 --- a/CveXplore/.schema_version +++ b/CveXplore/.schema_version @@ -1,4 +1,4 @@ { - "version": "1.8", + "version": "1.9", "rebuild_needed": true } diff --git a/CveXplore/core/database_actions/db_action.py b/CveXplore/core/database_actions/db_action.py index 19101da88..e8984cdcc 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 ed5468fb6..f1d0eca58 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 ) ) diff --git a/requirements/modules/mongodb.txt b/requirements/modules/mongodb.txt index 4e9d13d21..7930f795d 100644 --- a/requirements/modules/mongodb.txt +++ b/requirements/modules/mongodb.txt @@ -1 +1 @@ -pymongo>=4.5.0 \ No newline at end of file +pymongo>=4.8.0 \ No newline at end of file