Skip to content

Fix circular require warning in belongs_to.rb #8599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2025

Conversation

tagliala
Copy link
Contributor

@tagliala tagliala commented Jan 4, 2025

When running specs with RUBYOPTS='-w', numerous warnings are generated
due to a circular require between:

  • lib/active_admin/resource/belongs_to.rb
  • lib/active_admin/resource.rb

The warning message is:

lib/active_admin/resource/belongs_to.rb:2: warning: lib/active_admin/resource/belongs_to.rb:2: warning: loading in progress, circular require considered harmful - lib/active_admin/resource.rb

Based on the code history, there is no specific reason for the inverse
require from belongs_to to resource.

This change removes the unnecessary require to eliminate the warnings.

Closes #8598

When running specs with `RUBYOPTS='-w'`, numerous warnings are generated
due to a circular require between:
- `lib/active_admin/resource/belongs_to.rb`
- `lib/active_admin/resource.rb`

The warning message is:

```
lib/active_admin/resource/belongs_to.rb:2: warning: lib/active_admin/resource/belongs_to.rb:2: warning: loading in progress, circular require considered harmful - lib/active_admin/resource.rb
```

Based on the code history, there is no specific reason for the inverse
require from `belongs_to` to `resource`.

This change removes the unnecessary require to eliminate the warnings.

Closes #8598
@tagliala tagliala force-pushed the chore/8598-fix-circular-warning branch from cd78b79 to c3fd02c Compare January 4, 2025 11:48
@tagliala tagliala changed the title Remove circular require from resource/belongs_to Fix circular require warning in belongs_to.rb Jan 4, 2025
@@ -1,5 +1,4 @@
# frozen_string_literal: true
require_relative "../resource"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it possible that this is a breaking change? Like some use cases where resource/belongs_to is required individually without other resources?

Copy link
Member

Choose a reason for hiding this comment

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

I don't know. If the warning appears in normal usage of ActiveAdmin v4 and v3 (meaning a real app, not the test/dev app we generate for the project), we should address it in both versions. If we can see it stable in a real app on v3 then I think it's safe.

Copy link
Member

Choose a reason for hiding this comment

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

In commit 79c1a98 is where the circular require is introduced but doesn't seem to have any need for it so this removal should be safe. We can backport it as well.

Copy link

codecov bot commented Jan 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (5f54f91) to head (c3fd02c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8599      +/-   ##
==========================================
- Coverage   99.11%   99.11%   -0.01%     
==========================================
  Files         141      141              
  Lines        4074     4073       -1     
==========================================
- Hits         4038     4037       -1     
  Misses         36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

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

Thanks!

@tagliala tagliala merged commit ab49cb8 into master Jan 4, 2025
23 checks passed
@tagliala tagliala deleted the chore/8598-fix-circular-warning branch January 4, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Circular reference in resource/belongs_to.rb
2 participants