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

  1. Ensure that gitlab.cache_classes is set to false in gdk.yml.
  2. On master, start the GDK.
  3. Run gdk tail rails-web to watch the output.
  4. Change app/views/projects/show.html.haml (e.g. add && true to the if can? line)
  5. Access the project page.
  6. On master, this crashes with TypeError: Gitlab::Database::Type::IndifferentJsonb can't be referred to and Error reached top of thread-pool: stack level too deep (SystemStackError) errors.
  7. Repeat this test on this branch. No crashes should occur.
Edited by Stan Hu

Merge request reports

Loading