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

Define constants in separate module #47

Merged
merged 1 commit into from
Jul 30, 2024
Merged

Conversation

JonathonMA
Copy link
Contributor

This avoids a constant redefinition warning if the build.rake file is loaded twice (which, in our case, is more than annoying since we raise on warnings in development and test mode!)

@Faq
Copy link

Faq commented Nov 8, 2023

Could you post the actual warning you avoiding with this?

@JonathonMA
Copy link
Contributor Author

Sure, in our case we are using the handcuffs gem to allow phased migrations, which I believe is calling Rails.application.load_tasks a second time, which ends up looking something like this:

$ bin/rails db:test:load handcuffs:migrate[all]
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:1: warning: already initialized constant EXEC_PATH
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:1: warning: previous definition of EXEC_PATH was here
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:2: warning: already initialized constant CSS_LOAD_PATH
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:2: warning: previous definition of CSS_LOAD_PATH was here
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:3: warning: already initialized constant CSS_BUILD_PATH
/home/jma/.local/share/asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/dartsass-rails-0.5.0/lib/tasks/build.rake:3: warning: previous definition of CSS_BUILD_PATH was here

@calleluks
Copy link

We're seeing the same warnings in a project I'm working on. Thanks for fixing this!

@dhh
Copy link
Member

dhh commented Jan 1, 2024

Sorry, needs a rebase.

@dhh dhh merged commit 51637ca into rails:main Jul 30, 2024
26 checks passed
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.

4 participants