Skip to content

incorrect_dependent_option: Fix infinite recursion when association of the same class as model class#194

Open
fatkodima wants to merge 1 commit into
gregnavis:masterfrom
fatkodima:fix-infinite-recursion
Open

incorrect_dependent_option: Fix infinite recursion when association of the same class as model class#194
fatkodima wants to merge 1 commit into
gregnavis:masterfrom
fatkodima:fix-infinite-recursion

Conversation

@fatkodima

Copy link
Copy Markdown
Contributor

incorrect_dependent_options produces an infinite recursion and stack overflow when there is a :cascade foreign key and the association is of the same class as the owner model (for example, parent-child relationships).

@fatkodima fatkodima changed the title incorrect_dependent_options: Fix infinite recursion when association of the same class as model class incorrect_dependent_option: Fix infinite recursion when association of the same class as model class Dec 8, 2024
@gregnavis gregnavis added the crash An unexpected unhandled exception or simliar defect. label Dec 12, 2024
@gregnavis gregnavis added this to the 2.0 milestone Jan 4, 2025
@gregnavis gregnavis requested a review from Copilot August 5, 2025 17:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an infinite recursion issue in the incorrect_dependent_option detector that occurs when analyzing associations between models of the same class (e.g., parent-child relationships) with cascade foreign keys.

  • Adds a processing_list parameter to track models being processed to prevent infinite recursion
  • Implements early return when a model is already being processed in the recursive chain
  • Adds test coverage for the specific scenario of same-class associations with cascade foreign keys

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/active_record_doctor/detectors/incorrect_dependent_option.rb Modifies deletable? method to accept and use a processing list to prevent infinite recursion
test/active_record_doctor/detectors/incorrect_dependent_option_test.rb Adds test case for same-class associations with cascade foreign keys

Comment thread lib/active_record_doctor/detectors/incorrect_dependent_option.rb Outdated

@gregnavis gregnavis left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregnavis gregnavis force-pushed the fix-infinite-recursion branch from e0566cc to 3e8a4c8 Compare July 4, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

crash An unexpected unhandled exception or simliar defect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants