-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Rails 6 RC2 regression with multidb support #36757
Comments
I have been able to reproduce. Problem is, there is a class object which is not assigned to any constant ( This does not happen in On a first thought, we could perhaps fix /cc @eileencodes (just FYI) |
I'm experiencing the same issue on This is happening when using either |
This seems to be supposedly fixed, but I'm trying to upgrade my Rails app to 6.0 right now and am experiencing a similar issue. I have a method in a module that gets the DB Schema and returns it as a string. Calling it raises the Interestingly, this is happening in one of my Specs, but not in Marty is the name of the application. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
@shime I was also having trouble with the |
I have tried the original application with the current stable version and cannot reproduce anymore. I have also tried
and does not raise anything in both Let's close then. |
Thanks for pointing me in the right direction, @tconst. For posterity, here's what happened in my project. Our Gemfile contained wisper-activerecord which caused problems. Not sure how, but that gem clashes with Zeitwerk. The solution I used was to patch Active Support's Inflector to skip trying to constantize In the meantime we have removed Wisper from the Gemfile and we no longer experience issues. This is indeed not an issue with Zeitwerk, but with Wisper. Good call on closing this and thank you for your hard work on the new loader, @fxn. |
I can confirm @shime statement. The wisper active record causes the issue. A fix has been proposed in krisleech/wisper-activerecord#30 |
Can you help me understand the root cause of this? Given a vanilla |
@fxn , I have managed to replicate several times the issue having a migration like :
The issue resides in the fact that The culprit of the error is the below function:
And the values, while describing the issue:
If additional details are required, let us know LE: Using Rails V 6.0.3.1, |
Aaahhh, I have reproduced. It is enough to throw Wisper::ActiveRecord.extend_all in an initializer. With that setting, Wisper is involved in migrations because The name of the schema migration class is decorated in an unusual way. So the root problem here is:
Bottom line, this does not seem related to autoloading. The class objects created to manage I am not sure right now about which is the best way to address this. @eileencodes do you have any thoughts about this? Why are those classes defined that way? Could we make them conform to the AMo interface? |
Minimal way to reproduce in a vanilla Rails application (without Wisper):
You'll get
Reason is the name of the class is "primary::SchemaMigration" and therefore |
In Rails 6.0 the connection specification name for the ActiveRecord::Base class is `primary`. In 6.1 we've changed it to be `ActiveRecord::Base` to match how other classes behave. Due to the way the schema migration table and connection to that table are handled in Active Record we need to generate classes on the connection so those connections are able to find the correct table. Applications don't create the table, Rails does, and the default schema migration class inherits directly from Active Record. Since the default connection in 6.0 is named `primary` we end up with a class name of `primary::SchemaMigration` which is not a valid constant name and causes problems with Zeitwerk. I realized however that I never backported rails#38684 to 6.0 which skips the creation of the class for `ActiveRecord::Base` since it can use the default. This should fix the issue for Zeitwrk since we're no longer creating a `primary::SchemaMigration` class. The other databases in a multi-db application won't have issues because they use their actual class name, therefore causing no issues for Zeitwerk since it follows the Active Model naming pattern. Ref: rails#36757
I opened #39500, I think that will fix 6.0. |
I believe this is fixed. |
Steps to reproduce
Git clone test repo: https://github.com/navied/autoloaderbug
Expected behavior
Code should reload on code change in development without causing an error.
Actual behavior
When a code change happens with autoloader set to classic the first hit to the application causes a NameError:
System configuration
Rails version: 6.0.0 RC2
Ruby version: 2.5.5
The text was updated successfully, but these errors were encountered: