Skip to content

FOIMOD-4646: prevent deleted records from rejoining document sets#6097

Merged
alvesfc merged 3 commits intodevfrom
FOIMOD-4646_fix
Mar 18, 2026
Merged

FOIMOD-4646: prevent deleted records from rejoining document sets#6097
alvesfc merged 3 commits intodevfrom
FOIMOD-4646_fix

Conversation

@alvesfc
Copy link
Copy Markdown
Collaborator

@alvesfc alvesfc commented Mar 17, 2026

Summary

Fixes the FOI record delete flow so deleted records are actually removed from all document sets.

Root Cause

recordservice.update(...) was calling FOIRequestRecordGroups.remove_records_from_all_groups(...), but the loaded FOIRequestRecord.groups relationship was still attached to the ORM object. When FOIRequestRecord.create(...) later called db.session.merge(record), SQLAlchemy could merge that stale
relationship state back and recreate the join rows in FOIRequestRecordGroups.

Changes

  • Clear loaded groups on records during the isdelete=True path before the merge-based save runs
  • Add a regression test covering the delete flow and asserting stale group memberships are not carried into save

Files

  • request_api/services/recordservice.py
  • tests/services/test_recordservice.py

Verification

  • pytest tests/services/test_recordservice.py -q

Notes

This keeps the existing transaction shape intact:

  • record history is created
  • records are soft-deleted
  • document-set associations are removed
  • Doc Reviewer API call still happens after DB commit

@sonarqubecloud
Copy link
Copy Markdown

@alvesfc alvesfc merged commit 1f74d0b into dev Mar 18, 2026
4 checks passed
alvesfc added a commit that referenced this pull request Mar 30, 2026
FOIMOD-4646: prevent deleted records from rejoining document sets
alvesfc added a commit that referenced this pull request Mar 30, 2026
FOIMOD-4646: prevent deleted records from rejoining document sets
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.

2 participants