-
Notifications
You must be signed in to change notification settings - Fork 74
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
Use load when loading static service models #536
Conversation
@model ||= /MiqAeService(.+)$/.match(name)[1].gsub(/_/, '::').constantize | ||
@model ||= service_model_name_to_model(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a model ends up going through a Rails reload, will this be caching an old model? Or does Rails reload handle that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch. this will cache the old model and can cause problems.
we are caching quite a few classes in this code.
I am not really seeing these used too much, so not sure exactly why they are cached. e.g.: I don't see ar_model
used anywhere
The associations are cached, but I think those may be ok.
The load
change removes an infinite stacktrace. So that is more obvious when it is fixed, wondering if I will detect these other problems. Will run this code for a while.
|
||
def self.create_service_model(ar_model) | ||
file_path = model_to_file_path(ar_model) | ||
if File.exist?(file_path) | ||
require file_path | ||
model_name_from_active_record_model(ar_model).safe_constantize | ||
# class reloading in development causes require to no-op when it should load |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this always been true or is this new as of zeitwerk? I thought the whole point of class reloading is that it would internally re-load the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not in a path that reflect the package. This must be confusing the loader.
Do you want me to experiment with moving the files into a path that reflectst he package?
This method would change to:
def self.create_service_model(ar_model)
unless File.exist?(model_to_file_path(ar_model))
dynamic_service_model_creation(ar_model, service_model_superclass(ar_model))
end
end
So the caching issue is an existing issue. Not sure if it will be an issue but want to wait until I get a reproducer. The |
update:
We can probably fix this changing the way zeitwerk is implemented, but I was hoping to get this minimal change in first |
Checked commit kbrock@aea5b21 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint |
I'm good with merging this as is to get rid of the stack overflow. |
Backported to
|
Const get (cherry picked from commit 9e3f656)
Before
When development reloads classes,
MiqAeService
models run into an issue.MiqAeMethodService.const_missing
MiqAeServiceModelBase.create_service_model_from_name
MiqAeServiceModelBase.create_service_model
require file_name
HEREIf rails reloads a class, it unloads the service models, but since the file is still marked as required, the
require
does nothing.So the workflow changes as follows:
requre
is a no-opMiqAeMethodService.const_missing
To display the dialog for provisioning a Vm, automate is called inline in the webserver, so the webserver starts crashing with stack overflow errors.
After