Fix code reloading problems with custom database types
What does this MR do and why?
As described in https://github.com/rails/rails/issues/27337,
registering a custom, autoloaded ActiveRecord::Type in an initializer is not
safe for code reloading. Previously when
Gitlab::Database::Type::IndifferentJsonb was registered in the
ActiveRecord the registry and code reloading occurred, a TypeError
would occur because the registry had an old reference.
Let's avoid this code reloading issue by not using the ActiveRecord registry and instantiate the types explicitly.
References
Relates to:
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Ensure that
gitlab.cache_classesis set tofalseingdk.yml. - On
master, start the GDK. - Run
gdk tail rails-webto watch the output. - Change
app/views/projects/show.html.haml(e.g. add&& trueto theif can?line) - Access the project page.
- On
master, this crashes withTypeError: Gitlab::Database::Type::IndifferentJsonb can't be referred toandError reached top of thread-pool: stack level too deep (SystemStackError)errors. - Repeat this test on this branch. No crashes should occur.
Edited by Stan Hu