Skip to content

Fix MissingDependentDestroyChecker crash on polymorphic belongs_to associations#284

Merged
djezzzl merged 3 commits intomasterfrom
copilot/fix-missing-dependent-destroy-checker
Feb 27, 2026
Merged

Fix MissingDependentDestroyChecker crash on polymorphic belongs_to associations#284
djezzzl merged 3 commits intomasterfrom
copilot/fix-missing-dependent-destroy-checker

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

  • Fix preconditions in MissingDependentDestroyChecker to exclude polymorphic associations with !association.polymorphic?
  • Add spec test for polymorphic association case
  • Update CHANGELOG with thanks to original issue author (Andy Allan)
Original prompt

This section details on the original issue you should resolve

<issue_title>Error when running MissingDependentDestroyChecker on a polymorphic assocation</issue_title>
<issue_description>```
<===begin===>
Metadata:
model: Oauth2Application
association: owner
checker: DatabaseConsistency::Checkers::MissingDependentDestroyChecker
Stack trace:
/home/andy/.rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/activerecord-8.1.2/lib/active_record/reflection.rb:492:in `compute_class': Polymorphic associations do not support computing the class. (ArgumentError)

      raise ArgumentError, "Polymorphic associations do not support computing the class."
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    from /home/andy/.rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/activerecord-8.1.2/lib/active_record/reflection.rb:431:in `_klass'
    from /home/andy/.rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/activerecord-8.1.2/lib/active_record/reflection.rb:423:in `klass'
    from /home/andy/.rbenv/versions/3.2.7/lib/ruby/gems/3.2.0/gems/database_consistency-2.1.3/lib/database_consistency/checkers/association_checkers/association_checker.rb:30:in `block in foreign_key'


Full trace: [database_consistency_2026_02_25_16_19_58.txt](https://github.com/user-attachments/files/25550976/database_consistency_2026_02_25_16_19_58.txt)

Model definition: [Oauth2Application](https://github.com/openstreetmap/openstreetmap-website/blob/2f30ea19505e1ce849c8f96d27c5208714787637/app/models/oauth2_application.rb) 
Related model has_many: [User](https://github.com/openstreetmap/openstreetmap-website/blob/2f30ea19505e1ce849c8f96d27c5208714787637/app/models/user.rb#L76)
</issue_description>

<agent_instructions>Fix the issue by excluding polymorphic associations for the MissingDependentDestroyChecker; cover it with a spec.</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@djezzzl</author><body>
Nice catch, thank you! </body></comment_new>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: djezzzl <9407725+djezzzl@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error in MissingDependentDestroyChecker on polymorphic association Fix MissingDependentDestroyChecker crash on polymorphic belongs_to associations Feb 27, 2026
Copy link
Owner

@djezzzl djezzzl left a comment

Choose a reason for hiding this comment

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

@copilot Update changelog with proper thanks to original issue author

…association issue

Co-authored-by: djezzzl <9407725+djezzzl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 27, 2026

@copilot Update changelog with proper thanks to original issue author

Done in 2c8fe68. Added a changelog entry under [Unreleased] crediting Andy Allan for reporting the issue.

@djezzzl djezzzl marked this pull request as ready for review February 27, 2026 18:46
@djezzzl djezzzl merged commit debff3a into master Feb 27, 2026
13 checks passed
@djezzzl djezzzl deleted the copilot/fix-missing-dependent-destroy-checker branch February 27, 2026 18:46
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.

Error when running MissingDependentDestroyChecker on a polymorphic assocation

2 participants