Skip to content

Fix Session.delete() in gap analysis cleanup (#826, rebased #827) - #1099

Merged
northdpole merged 2 commits into
mainfrom
maintainer/fix-827-ga-delete
Sep 13, 2026
Merged

northdpole merged 2 commits into
mainfrom
maintainer/fix-827-ga-delete

Conversation

@northdpole

Copy link
Copy Markdown
Collaborator

Summary

  • Rebase of #827 onto current main.
  • session.delete() returns None in SQLAlchemy 2.x, so the old result.rowcount log never ran. Count deletions explicitly and log once.
  • Test inserts GapAnalysisResults rows directly because add_gap_analysis_result now skips empty primary payloads.

Original work by @akashrajeev. Maintainer rebase so we can land it without waiting on a conflicted fork.

Test plan

  • python -m unittest application.tests.db_test.TestDB.test_delete_gapanalysis_results_for_deletes_and_logs_count
  • CI db_test / full make test

Closes #826
Supersedes #827

Made with Cursor

SQLAlchemy 2.x session.delete() returns None, so the old rowcount log never ran. Count deletions explicitly. Test inserts cache rows directly because add_gap_analysis_result skips empty primary payloads.

Co-authored-by: northdpole <morfeas3000@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: d1008d66-2fb1-474b-a987-47360ccd5e0e

📥 Commits

Reviewing files that changed from the base of the PR and between 96a3344 and b006dee.

📒 Files selected for processing (2)
  • application/database/db.py
  • application/tests/db_test.py

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Summary by CodeRabbit

  • Bug Fixes

    • Gap-analysis result cleanup now accurately reports the number of deleted records.
    • Deletion logging is consolidated into a single message that includes the affected node name.
    • Unrelated gap-analysis results remain preserved during cleanup.
  • Tests

    • Added coverage verifying deletion counts, retained records, and cleanup logging.

Walkthrough

The cleanup method now counts deleted gap-analysis rows and logs one aggregate message with the node name. A new test verifies matching-row deletion, unrelated-row preservation, the return count, and logging.

Changes

Gap analysis cleanup

Layer / File(s) Summary
Deletion count and validation
application/database/db.py, application/tests/db_test.py
The cleanup method no longer inspects Session.delete() results. It counts deleted rows and logs one aggregate message. The test verifies two matching rows are deleted, one unrelated row remains, the count is returned, and the log includes the count and node name.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 2489c

The cleanup explicitly counts matching rows, deletes them correctly, and has focused coverage for deletion and aggregate logging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the SQLAlchemy Session.delete() fix in gap analysis cleanup. It is specific and related to the main change.
Description check ✅ Passed The description accurately explains the rebase, the SQLAlchemy 2.x behavior, the explicit deletion count, the logging change, and the test plan.
Linked Issues check ✅ Passed The PR satisfies #826. In delete_gapanalysis_results_for() it stops inspecting the session.delete() return value, increments a local count for each matching row, and emits one log message with the…
Out of Scope Changes check ✅ Passed The changes stay within the scope of #826. The production change is localized to application/database/db.py. The added application/tests/db_test.py coverage directly verifies deletion and logging …
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch maintainer/fix-827-ga-delete

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.

* origin/main:
  Rework OWASP mapping importers to load shared eval fixtures.
@northdpole
northdpole merged commit 92f12be into main Sep 13, 2026
12 checks passed
@northdpole
northdpole deleted the maintainer/fix-827-ga-delete branch September 13, 2026 14:46
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.

Fix incorrect Session.delete() result handling in gap analysis cleanup

2 participants