Project

General

Profile

Refactor #28565

Don't use AR's association_scope

Added by Anonymous 8 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Rails
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

association_scope is private in Rails 6 (since https://github.com/rails/rails/commit/0b4cfa2ba3e978386240e0e56a409616cc32fd02):

[...]
NoMethodError: private method `association_scope' called for #<ActiveRecord::Associations::HasManyAssociation:0x00000000100e57f8>
    lib/core_extensions.rb:41:in `block in before_destroy'
    lib/core_extensions.rb:40:in `each'
    lib/core_extensions.rb:40:in `before_destroy'
[...]


Related issues

Related to Foreman - Bug #11188: on deleting a capsule: Operation FAILED: ERROR: update or delete on table "smart_proxies" violates foreign key constraint "hosts_puppet_ca_proxy_id_fk" on table "hosts"Closed
Blocks Foreman - Tracker #24837: Rails 6.0 TrackerClosed

Associated revisions

Revision bcfbba25 (diff)
Added by Tomer Brisker 7 months ago

Fixes #28565 - Avoid association_scope method

ActiveRecord::Associations#association_scope has been changed to private
method in Rails 6. We replace it by explicitly creating the
AssociationScope we need.
Additionally, refactored EnsureNotUsedBy callback to be more efficient
by only loading the authorized associations' ids once instead of loading
all of the records again for every existing association still present.

History

#1 Updated by Anonymous 8 months ago

  • Related to Bug #11188: on deleting a capsule: Operation FAILED: ERROR: update or delete on table "smart_proxies" violates foreign key constraint "hosts_puppet_ca_proxy_id_fk" on table "hosts" added

#2 Updated by Anonymous 8 months ago

#3 Updated by Tomer Brisker 7 months ago

  • Assignee set to Tomer Brisker
  • Status changed from New to Assigned

#4 Updated by The Foreman Bot 7 months ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/7318 added

#5 Updated by The Foreman Bot 7 months ago

  • Fixed in Releases 2.0.0 added

#6 Updated by Tomer Brisker 7 months ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF