Repository navigation
fix(cvedb): deduplicate EPSS metrics on upgrade - #6190
Open
MegharajPN wants to merge 1 commit into
Open
MegharajPN wants to merge 1 commit into
MegharajPN wants to merge 1 commit into
Conversation
Existing databases created before cve_metrics had a primary key could accumulate duplicate rows for the same CVE and metric. CREATE TABLE IF NOT EXISTS and latest_schema() never upgraded those tables, so INSERT OR REPLACE kept appending new EPSS scores. Add the missing comma in the table definition, add an idempotent migration that keeps the newest row per (cve_number, metric_id) and creates a unique index if needed, and run it during database init and CVE list refresh. Fixes ossf#5490 Signed-off-by: MegharajPN <meghrajdvg.pn253@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cve_metricstable definition.(cve_number, metric_id)rows, keeping the most recently inserted value, and creates a unique index when one is missing.init_database()andget_cvelist_if_stale().Root cause
cve_metricswas defined without an enforced unique key in older databases (CREATE TABLE IF NOT EXISTS/latest_schema()never upgraded it), soINSERT OR REPLACEappended a new EPSS row on every refresh instead of replacing the previous value.Tests
test_cve_metrics_keep_only_latest_valuetest_init_database_deduplicates_legacy_cve_metrics(fails on the base commit)pytest test/test_cvedb.py test/test_source_epss.py -q-> 27 passed, 2 skippedblack --check,isort --check-only,flake8, andgit diff --checkpassFixes #5490