incorrect_dependent_option: Fix infinite recursion when association of the same class as model class#194
Open
fatkodima wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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_listparameter 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 |
gregnavis
requested changes
Aug 5, 2025
…of the same class as model class
e0566cc to
3e8a4c8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
incorrect_dependent_options produces an infinite recursion and stack overflow when there is a
:cascadeforeign key and the association is of the same class as the owner model (for example, parent-child relationships).