refactor(scan): deduplicate insecure_full.json loading - #901
Open
Rafael-Jost wants to merge 1 commit into
Open
Conversation
The lazy-load block for insecure_full.json was duplicated verbatim in two branches of PythonFile.__find_dependency_vulnerabilities__, with a third near-identical copy in remediate(). Extract it into PythonFile._load_full_db() so the cache lookup and its arguments live in a single place. The early return stays at each call site rather than moving into the helper: returning from the helper would let callers continue with db_full unset. remediate() previously loaded the same file without logging. It now emits the same DEBUG message as the other call sites when the cache is unavailable. No other behavior change. Add TestLoadFullDb covering both outcomes: the loaded database is returned as-is, and a missing cache yields None plus the DEBUG log.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Description
safety/scan/ecosystems/python/main.pyloaded theinsecure_full.jsoncache in three places with duplicated code: twice inside
PythonFile.__find_dependency_vulnerabilities__and once inPythonFile.remediate. The cache name, theskip_time_verification=Trueargument and the DEBUG log message were repeated at each site, so any
change to how that cache is read had to be made in three places.
This extracts the lookup into a
PythonFile._load_full_db()helper.Two notes on the approach:
returnstays at each call site rather than moving into thehelper. Returning from inside the helper would let callers continue
executing with
db_fullunset.remediate()previously loaded the same file without logging. It nowemits the same DEBUG message as the other two call sites when the cache
is unavailable.
No other behavior change.
Type of Change
Related Issues
Part of #575
Testing
Adds
TestLoadFullDbtotests/scan/ecosystems/python/test_main.py,covering both outcomes:
get_from_cacheis called with
db_name="insecure_full.json", skip_time_verification=TrueNoneis returned and the DEBUG message is loggedpytest tests/scan/ecosystems/python/test_main.pypasses locally (7 tests,Python 3.14.3).
Checklist
Additional Notes
CHANGELOG.mdwas intentionally left untouched — it states it is generatedautomatically and should not be edited manually.
ruff checkreports pre-existing findings on both touched files(
UP006,UP035,B006,DTZ003,SIM102,SIM118,I001). They areidentical on
mainand this PR introduces no new ones, so I left themalone to keep the diff focused. Happy to fix them in a separate PR if you'd
like.
ruff format --checkis clean on both files.