-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Zeitwerk, omniauth and multiple DBs (connects_to) #275
Comments
I need to read this with some time, but let me ask a couple of questions:
|
Hello Xavier, thank you.
|
Is |
It is defined in
|
OK, that is not good because middleware is not reloaded. In Rails 7 you won't be able to configure the provider (precisely, to avoid these situations). You should tell the autoloader to ignore
and issue a Not saying this solves the whole situation, but for starters it fixes something. |
I have a workaround, but it doesn't seem the right. I added the following require statements (with the specific order, so that when # config/initializers/omniauth.rb
# ... other require statements
require "concerns/fine_grained_validations"
require "concerns/policy_scope_support"
require "application_record" If you have any other insights, I will appreciate it if you chime in. Thank you. |
OK, we need to polish a bit more. No reloadable code should be loaded while the application is booting. The file Rails.autoloaders.main.ignore("#{config.root}/lib/shield_settings.rb") Let's iterate until we reach a more controlled setup to address the issue with the migrations. Ideally, no warning should be issued. This section of the upgrdading guide has some tips, but I am here to help you anyway ❤️. |
Since this is something related to how the Rails application is configured, I have moved the issue to the Rails repository (rails/rails#49310). |
I am pretty sure that the connection closed issue is fixed by rails/rails#45450 but it can't be backported to 7-0-stable because it's too big of a change in internal behavior. Upgrading to 7.1.x should fix that particular issue. |
Hello and thank you for zeitwerk.
I am upgrading our Rails 6.1 application to use zeitwerk and am running into a strange issue that won't let me run specific migrations. The involved parts as far as I can tell are zeitwerk, multiple connections with
connects_to
and omniauth (for which I have read #143, but don't see how it's related).Any suggestions are welcome.
The classes
In omniauth, we are using a custom strategy:
The
OmniAuth::Strategies::ShieldOIDC
then uses constants defined in the following module:Member
is a model, which inherits fromApplicationRecord
, which contains theconnects_to
:The problem
When I run the migrations, all migrations run successfully, but I get:
2023-09-15 10:54:18.004987 W [69836:10220] Rails -- DEPRECATION WARNING: Initialization autoloaded the constants FineGrainedValidations, PolicyScopeSupport, ApplicationRecord, Sanitizable, FavoriteJobs, MemberJobs, WorkableUtils, WorkableUtils::InitialsExtractor, DefaultSettings, RecruitingAdmin, Syncable, Emailable, Sampleable, EmailValidator, and Member.
In my understanding, these are from
lib/shield_settings.rb
and in particular theMember::
prefix, which cases the Member to be loaded during initialization, which is deprecated.Instead, I defined the constants I was retrieving from
Member
withinlib/shield_settings.rb
, so that I am not loading the model during initialization. Now ~30 migrations pass and the following fails:with:
Observations
Observation 1
All the migrations will pass if I comment out the
connects_to
fromApplicationRecord
.Observation 2
Furthermore, all the migrations pass (with the
DEPRECATION WARNING
shown above ifMember
orApplicationRecord
or any other model are referenced in thelib/shield_settings.rb
.Observation 3
If I comment out the code snippet from the offending migration, the migration passes. The strange thing is that the iteration is empty, so the loop will not run. Now another ~20 migrations pass, and then the following migration will fail:
the error now is:
The text was updated successfully, but these errors were encountered: