Issue when upgrading to 3.13 (and the fix)

Problem:
Upgrading to Foreman 3.13 ran into an issue with the rake db:migrate scripts. Failed with an error of undefined method ‘organization’

Expected outcome:
For the db:migrate to complete
Foreman and Proxy versions:

Foreman and Proxy plugin versions:
3.13 and Katello 4.15

Distribution and version:
RHEL 9

Other relevant data:
Error from foreman-installer/katello.log

2025-01-14 20:23:33 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: StandardError: An error has occurred, this and all later migrations canceled:
2025-01-14 20:23:33 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns:
2025-01-14 20:23:33 [INFO  ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: undefined method `organization' for #<Katello::Util::FakeActivationKey id: 8, name: "Red Hat
Enterprise Linux", description: nil, organization_id: 1, environment_id: 4, created_at: "2023-08-22 21:10:28.552603000 +0000", updated_at: "2023-08-22 21:27:43.731203000 +0000", user_id: 5, max_hosts: nil, content_view_id: nil, cp
_id: "8a48b82f8a1dcacf018a1f15ac5a0081", release_version: nil, unlimited_hosts: true, auto_attach: true, purpose_role: "Red Hat Enterprise Linux Server", purpose_usage: "Production">

The root of the issue is that we have manifests installed from RedHat that created RedHat content view activation keys that don’t actually have any content views associated with them. When they migration scripts were trying to migrate to new stuff needed for multiple content views it was blowing up. The solution was in editing '/usr/share/gems/gems/katello-4.15.0/app/lib/katello/util/cveak_migrator.rb"

Comment out 3 lines and add one:

          #default_content_view = ak.organization.default_content_view
          #library = ak.organization.library
          #ak&.update_columns(content_view_id: default_content_view&.id, environment_id: library&.id)
          ak&.update_columns(content_view_id: 1, environment_id: 1)

Basically what is happening is, it’s trying to get info that doesn’t exist in the activation keys and throwing an error. This hack just changed to content_view_id and environment_id to be 1 for any of these keys (which in my case is “Default Organization View” and “Library”.

Not sure what the proper fix is, but, this got me working on 3.13 with RHEL.

Thanks so much for catching this!

I have opened Bug #38147: FakeActivationKey doesn't respond to #organization method - Katello - Foreman and Fixes #38147 - correctly find org on FakeActivationKey by jeremylenz · Pull Request #11280 · Katello/katello · GitHub