-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1087 from TG1999/fix/1086
Add migrations to remove corrupted advisories #1086
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...abilities/migrations/0038_remove_corrupted_advisories_with_incorrect_refs_and_severity.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# VulnerableCode is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/vulnerablecode for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
from django.db import migrations | ||
|
||
from vulnerabilities.severity_systems import SCORING_SYSTEMS | ||
|
||
class Migration(migrations.Migration): | ||
|
||
def remove_advisories(apps, schema_editor): | ||
Advisory = apps.get_model("vulnerabilities", "Advisory") | ||
deletables = [] | ||
for advisory in Advisory.objects.iterator(chunk_size=1000): | ||
for ref in advisory.references: | ||
if not ref["url"]: | ||
deletables.append(advisory.pk) | ||
break | ||
for sev in ref["severities"]: | ||
if sev["system"] not in SCORING_SYSTEMS: | ||
deletables.append(advisory.pk) | ||
break | ||
Advisory.objects.filter(pk__in=deletables).delete() | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0037_advisory_weaknesses_weakness"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(remove_advisories, reverse_code=migrations.RunPython.noop), | ||
] |
This file contains 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