Investigate orphaned work item events
Problem
We have found orphaned work item events in the database despite having dependent: :delete_all configured on the association between issues and events.
Related to: Fetching issue events fails with error 500 (#581920 - closed)
Investigation Needed
-
Identify bypass scenarios: Determine if there are places in the codebase where issues are being deleted in ways that bypass Rails callbacks (e.g., direct SQL deletion, bulk operations)
-
Audit deletion patterns: Review all code paths that delete issues to ensure they properly trigger the dependent destruction of associated events
-
Database consistency check: Verify the current state of orphaned events in the database and their characteristics
Expected Behavior
When work item is destroyed, all associated events should be automatically deleted due to the dependent: :delete_all configuration.
Actual Behavior
Events are remaining in the database after their target issues have been deleted, leading to orphaned records and risks downstream bugs.
Acceptance Criteria
-
Identify the root cause of orphaned events -
Fix any deletion patterns that bypass Rails callbacks -
Implement safeguards to prevent future orphaned events -
(Optional) Clean up existing orphaned events in the database
Description was generated using AI