Skip to content
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

Solve circular require warning. #491

Merged
merged 2 commits into from Feb 26, 2024

Conversation

martijnbolhuis
Copy link
Contributor

See issue #490.

@@ -4,7 +4,6 @@
return
end

require "dotenv"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This require statement shouldn't be necessary since it is already required as the entrypoint of the gem. I suspect that it is still there from the time that Rails integration was a separate gem. Removing this gets rid of the warning in my app and does not seem to break the specs in the dotenv gem.

@bkeepers bkeepers merged commit 96b05b0 into bkeepers:main Feb 26, 2024
12 checks passed
@bkeepers
Copy link
Owner

Thanks @martijnbolhuis! I'll get this released soon.

that-jill pushed a commit to powerhome/power-web-development-interview that referenced this pull request Feb 27, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [dotenv-rails](https://togithub.com/bkeepers/dotenv) | `3.0.2` ->
`3.1.0` |
[![age](https://developer.mend.io/api/mc/badges/age/rubygems/dotenv-rails/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/rubygems/dotenv-rails/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/rubygems/dotenv-rails/3.0.2/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/rubygems/dotenv-rails/3.0.2/3.1.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>bkeepers/dotenv (dotenv-rails)</summary>

###
[`v3.1.0`](https://togithub.com/bkeepers/dotenv/blob/HEAD/Changelog.md#310)

**What's Changed**

- Fix regression with semantic-logger, allow setting custom logger by
[@&#8203;bkeepers](https://togithub.com/bkeepers) in
[bkeepers/dotenv#494
    ```ruby
    ```

###
[`v3.0.3`](https://togithub.com/bkeepers/dotenv/blob/HEAD/Changelog.md#303)

[Compare
Source](https://togithub.com/bkeepers/dotenv/compare/v3.0.2...v3.0.3)

**What's Changed**

- Solve circular require warning by
[@&#8203;martijnbolhuis](https://togithub.com/martijnbolhuis) in
[bkeepers/dotenv#491
- Use tagged logger already configured on Rails by
[@&#8203;kriansa](https://togithub.com/kriansa) in
[bkeepers/dotenv#489
- Fix exception on startup for Rails 7.1.0 by
[@&#8203;bkeepers](https://togithub.com/bkeepers) and
[@&#8203;zspencer](https://togithub.com/zspencer) in
[bkeepers/dotenv#492

**New Contributors**

- [@&#8203;zspencer](https://togithub.com/zspencer) made their first
contribution in
[bkeepers/dotenv#492
- [@&#8203;martijnbolhuis](https://togithub.com/martijnbolhuis) made
their first contribution in
[bkeepers/dotenv#491
- [@&#8203;kriansa](https://togithub.com/kriansa) made their first
contribution in
[bkeepers/dotenv#489

**Full Changelog**:
bkeepers/dotenv@v3.0.2...v3.0.3

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/powerhome/power-web-development-interview).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yMTIuMCIsInVwZGF0ZWRJblZlciI6IjM3LjIxMi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@Burgestrand
Copy link

Burgestrand commented Mar 26, 2024

Hi! This change caused me some issues, so I'll write it here in lack of a better place in case somebody comes across the same problem.

It manifested as my test suite not being able to run because environment variables from .env.test.local weren't loading. I was confused, but we very clearly were loading dotenv-rails, and I assumed that would also load dotenv/rails, which it no longer does.

The cause of events that lead to this issue is:

  • I'm using Rails and rspec.
  • I've got a spec/spec_helper.rb that doesn't load Rails.
  • I've got a spec/rails_helper.rb that does require "spec_helper", and then proceeds to load Rails.

The reasoning is:

  • Tests that don't need Rails don't load it, so they require "spec_helper".
  • Tests that do need Rails will require "rails_helper"

Unfortunately inside of spec/spec_helper.rb we're also using dotenv, so the series of events were:

  1. Load a Rails-running test, which does require "rails_helper"
  2. ... rails_helper then does require "spec_helper"
  3. ... spec_helper then does require "dotenv", at this point Rails::Railtie is not defined, since Rails isn't loaded yet.
  4. ... some time later config/application.rb is loaded
  5. ... which does Bundler.require(*Rails.groups)
  6. ... which does require "dotenv-rails" (we now want the Railtie)
  7. ... and dotenv-rails simply does require "dotenv", but since dotenv is already loaded it stops here.

The end-result is that dotenv/rails is never required, even though we did require dotenv-rails.

The fix for us is to adjust our Gemfile:

gem "dotenv", require: %w[dotenv dotenv/rails]

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.

Ruby warning: circular require considered harmful
3 participants