-
Notifications
You must be signed in to change notification settings - Fork 26
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
Rakefile seems to be loaded twice #130
Comments
@dmke thanks for a detailed explanation + steps to reproduce. I think you're 100% right on the cause + fix. Would you mind putting up a PR for this? I think just that change itself should be sufficient for supporting both the direct gem invocation ( |
Will do, just don't know when :) |
No worries, whenever you have a moment it would be appreciated. It doesn't have to be much more than just the conditional change you proposed. It's nice for me when other folks feel empowered to add PRs :). |
I'm revisiting this issue now that I'm done with refactors. The more that I think about this, the more I'm beginning to wonder why I'll do some more investigation but that piece of code is 15+ years old: |
The
Loading I believe, the def call(_)
require_relative "./config/environment.rb" if File.exist?("./config/environment.rb")
end since ActiveSupport will already be loaded unconditionally in I'll try to experiment with that later. |
Thanks for trying to dig into this. I spent some time today and will give it another go later this week, but I realized I was mistaken by what actually happens. In the commit I referenced above, it actually loads the -- Unless I'm mistaken, there's 3 ways to run AnnotateRb with the context of a Rails app:
I don't usually test 2) but I believe there might be setups that do this, especially if there's Rails engines. I'll try and understand the behavior of the |
@dmke Okay, I think I got a better sense of how things work given those 3 different entry points. The
There's no double loading of
|
See #130 for problem discussion. This also drops a lot of legacy and/or unnecessary code from `AnnotateRb::RakeBootstrapper`.
I released a new gem version, |
Thanks, will try later! |
So, it took a moment, but it works as expected. Thanks again! |
I encountered the issue where |
I have some Rake files, which define some constants. When running
bin/rails db:migrate
, the output is flooded with warnings of already defined constants.This doesn't happen when calling
bundle exec annotaterb models
.Commands
Reproduction
rails new --minimal --api
or similar)rails g model User name email:unique
) (not sure if this is necessary)lib/tasks/codegen.rake
(the actual name is not relevant, it must end in.rake
though):bin/rails db:{create,migrate}
). Observe no warning.annotaterb
, configureskip_on_db_migrate: false
.bin/rails db:migrate
). Observe warnings.Breakdown
Adding a
puts caller
before theCodegen::RAILS_ROOT
constant reveals the following:The culprit likely lies in
rake_bootstrapper.rb
(omitting some details), which loads the Rakefile unconditionally if it exists:AFAICT, the reason for this is to ensure that the
environment
task will be defined (throughRails.application.load_tasks
in standard Rails-generated Rakefiles).We could eliminate the warning by checking whether that task is defined:
This works with both
bin/rails db:migrate
andbundle exec annotaterb models
. I'm not sure whether are other forms of invocations, so this might need a more thorough testing.Version
The text was updated successfully, but these errors were encountered: