Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(worker): remove stale import findings for successful record #2945

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docker/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ def _do_update(self, source_repo, repo, vulnerability, relative_path,

osv.update_affected_commits(bug.key.id(), result.commits, bug.public)
self._notify_ecosystem_bridge(vulnerability)
self._maybe_remove_import_findings(bug)

def _notify_ecosystem_bridge(self, vulnerability):
"""Notify ecosystem bridges."""
Expand All @@ -562,6 +563,14 @@ def _notify_ecosystem_bridge(self, vulnerability):
push_topic,
data=json.dumps(osv.vulnerability_to_dict(vulnerability)).encode())

def _maybe_remove_import_findings(self, vulnerability: osv.Bug):
"""Remove any stale import findings for a successfully processed Bug,"""

finding = osv.ImportFinding.get_by_id(vulnerability.id())
if finding:
logging.info('Removing stale import finding for %s', vulnerability.id())
finding.key.delete()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a random thought, will we ever need to query historical finding data? For example, to evaluate how many records the linter helped fix?


def _do_process_task(self, subscriber, subscription, ack_id, message,
done_event):
"""Process task with timeout."""
Expand Down
22 changes: 22 additions & 0 deletions docker/worker/worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,28 @@ def test_analysis_crash_handling(self):

self.expect_dict_equal('analysis_crash_handling', bug._to_dict())

def test_update_clears_stale_import_finding(self):
"""A subsequent successful update removes the now stale import finding."""

# Add a pre-existing record import finding.

osv.ImportFinding(
bug_id='OSV-123',
source='source',
findings=[osv.ImportFindings.INVALID_JSON],
first_seen=osv.utcnow(),
last_attempt=osv.utcnow()).put()

# Simulate a successful record update.

self.test_update()

# Check the pre-existing finding is no longer present.

self.assertIsNone(
osv.ImportFinding.get_by_id('OSV-123'),
'Stale import finding still present after successful record processing')


if __name__ == '__main__':
ds_emulator = tests.start_datastore_emulator()
Expand Down
Loading