.vbw-planning/milestones/polish-and-reliability/phases/04-bug-fixes-and-polish/PLAN-02.md
Investigate and fix the 500 error when deleting sources, particularly when host apps extend engine models with additional FK references.
Files: app/models/source_monitor/source.rb, app/controllers/source_monitor/sources_controller.rb
Examine the full dependent: :destroy chain on Source:
has_many :all_items (dependent setting?)has_many :fetch_logs (dependent setting?)has_many :scrape_logs (dependent setting?)has_many :health_check_logs (dependent setting?)has_many :log_entries (dependent setting?)has_one_attached :favicon (Active Storage)Check if any association is missing dependent: :destroy or if the ordering causes FK violations. Pay special attention to:
Based on investigation findings:
dependent: optionsdependent: :destroy_async for large collections if appropriatebefore_destroy callback to handle cleanup ordering if neededFiles: app/controllers/source_monitor/sources_controller.rb
Wrap @source.destroy in proper error handling:
if @source.destroy
# existing turbo stream / html response
else
# error response with useful message
end
Also add rescue ActiveRecord::InvalidForeignKey to catch host-app FK violations and provide a helpful error message like "Cannot delete source: other records still reference it."