Skip to content

refactor(scan): deduplicate insecure_full.json loading - #901

Open
Rafael-Jost wants to merge 1 commit into
pyupio:mainfrom
Rafael-Jost:code-refact-first-issue
Open

refactor(scan): deduplicate insecure_full.json loading#901
Rafael-Jost wants to merge 1 commit into
pyupio:mainfrom
Rafael-Jost:code-refact-first-issue

Conversation

@Rafael-Jost

Copy link
Copy Markdown

Description

safety/scan/ecosystems/python/main.py loaded the insecure_full.json
cache in three places with duplicated code: twice inside
PythonFile.__find_dependency_vulnerabilities__ and once in
PythonFile.remediate. The cache name, the skip_time_verification=True
argument 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:

  • The early return stays at each call site rather than moving into the
    helper. Returning from inside the helper would let callers continue
    executing with db_full unset.
  • remediate() previously loaded the same file without logging. It now
    emits the same DEBUG message as the other two call sites when the cache
    is unavailable.

No other behavior change.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor
  • Other (please describe):

Related Issues

Part of #575

Testing

  • Tests added or updated
  • No tests required

Adds TestLoadFullDb to tests/scan/ecosystems/python/test_main.py,
covering both outcomes:

  • cache hit — the loaded database is returned as-is, and get_from_cache
    is called with db_name="insecure_full.json", skip_time_verification=True
  • cache miss — None is returned and the DEBUG message is logged

pytest tests/scan/ecosystems/python/test_main.py passes locally (7 tests,
Python 3.14.3).

Checklist

  • Code is well-documented
  • Changelog is updated (if needed)
  • No sensitive information (e.g., keys, credentials) is included in the code
  • All PR feedback is addressed

Additional Notes

CHANGELOG.md was intentionally left untouched — it states it is generated
automatically and should not be edited manually.

ruff check reports pre-existing findings on both touched files
(UP006, UP035, B006, DTZ003, SIM102, SIM118, I001). They are
identical on main and this PR introduces no new ones, so I left them
alone to keep the diff focused. Happy to fix them in a separate PR if you'd
like. ruff format --check is clean on both files.

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.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 67b252c2-681e-49e1-9fe0-84126c00d3da

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant