Skip to content

Fix and ban deprecation warning "Passing an ActiveRecord object"

Peter Leitzen requested to merge pl-fix-deprecation-passing-quote-ar into master

What does this MR do and why?

This commit fixes the following deprecation warning

DEPRECATION WARNING: Passing an Active Record object to `quote` directly
is deprecated

emitted by https://github.com/rails/rails/blob/v6.1.6.1/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L13-L16

It also bans this deprecation warning to avoid future instances.

Moreover, it also bans the deprecation warning proactively:

Passing an Active Record object to `type_cast` directly is deprecated

emitted by https://github.com/rails/rails/blob/v6.1.6.1/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L28-L31

Please see #369970 (closed) for more information.

How to set up and validate locally

  1. Revert the code change via git checkout master -- lib/gitlab/object_hierarchy.rb

  2. Run bin/rspec --order defined spec/models/group_spec.rb -e ancestors

  3. Observe failure

  1) Group traversal queries linear behaves like namespace traversal #ancestors_upto with use_traversal_ids_for_ancestors_upto enabled includes ancestors upto but excluding the given ancestor
     Failure/Error: connection.send(...)

     ActiveSupport::DeprecationException:
       DEPRECATION WARNING: Passing an Active Record object to `quote` directly is deprecated
       and will be no longer quoted as id value in Rails 7.0.
        (called from block in write_using_load_balancer at /home/peter/devel/gitlab/gdk/gitlab/lib/gitlab/database/load_balancing/connection_proxy.rb:120)
     Shared Example Group: "#ancestors_upto" called from ./spec/support/shared_examples/namespaces/traversal_examples.rb:248

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports