Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37825 - Upgrade Rails to 7.0 #10299

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

ofedoren
Copy link
Member

Based on #10131, but with additional commit needed for Rails upgrade.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #9328 I also updated spring. Is that not needed? I recall running into it, but that could have been a Ruby thing or I was just looking at changelogs.

@@ -5,7 +5,7 @@ module Token
included do
has_one :token, :foreign_key => :host_id, :dependent => :destroy, :inverse_of => :host, :class_name => 'Token::Build'

scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc.to_s(:db)).select('hosts.*') }
scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc.to_fs(:db)).select('hosts.*') }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: there's .to_fs in Rails. I wonder if Rails is smart enough to understand

Suggested change
scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc.to_fs(:db)).select('hosts.*') }
scope :for_token, ->(token) { joins(:token).where(:tokens => { :value => token }).where("expires >= ?", Time.now.utc).select('hosts.*') }

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried if moving the settings into initializers works with Rails 6.1?

Comment on lines 94 to +95
class ::FakePlugin; end
class ::FakePlugin::FakeModel; end
class ::FakePlugin::FakeModel < ApplicationRecord; end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this even be

module FakePlugin
  class FakeModel < ApplicationRecord
  end
end

@ofedoren ofedoren force-pushed the rails-7.0 branch 2 times, most recently from b2971c8 to c93acc6 Compare September 16, 2024 14:10
@ofedoren ofedoren changed the title Rails 7.0 Fixes #37825 - Upgrade Rails to 7.0 Sep 16, 2024
@ofedoren ofedoren marked this pull request as ready for review September 16, 2024 15:02
@ofedoren ofedoren requested a review from a team as a code owner September 16, 2024 15:02
@ekohl ekohl mentioned this pull request Sep 17, 2024
@ofedoren
Copy link
Member Author

There left only one test failure, I'm looking into it, for now I've got no clue :/

Apart from that, it's ready unless we want to be more correct and apply/incorporate these changes: https://railsdiff.org/6.1.7.8/7.0.8.4

@ofedoren
Copy link
Member Author

Now it fails due to ldap_fluff, since it's locked on active_support < 7 (https://github.com/theforeman/ldap_fluff/blob/master/ldap_fluff.gemspec#L21). Weird that it didn't fail before...

Also, @ekohl and @adamruzicka or maybe @ShimShtein, since you have more experience with the codebase and Rails, could you please help me get why the test fails? I'll be out for the next week (30.09 - 06.10), so I hope we won't waste that week.

Regarding the test: I think it's due to code reloading happening somewhere in the test:units suit since running each of test/models, test/helpers and test/unit separately works, it works even if run rails test test/models test/helpers test/unit, which is the same what rake test:units does. Setting test_order = :sorted doesn't help. Also, I've noticed that for some reason it can pass twice in a row, but another run would fail.

@@ -124,11 +124,6 @@ class Jail < ::Safemode::Jail
:children_mac_addresses, :nic_delay, :fqdn, :shortname, :type, :managed?, :bond?, :bmc?, :provision?
end

# include STI inheritance column in audits
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, re-visiting this, I think that's not a correct solution :/ Although, I didn't find this method being overridden for other STIs...

@ofedoren
Copy link
Member Author

ofedoren commented Oct 9, 2024

Finally, it's green and with minimal changes needed. Ready for full review.

@@ -15,13 +15,5 @@ def new(attributes = nil, &block)
super
end
end

def save(*args, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this was the whole problem? That it set an instance variable on the class? That looks nasty and I wonder how that worked in the past.

From reading the Rails source I get the impression should handle this itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems so. I couldn't find a reason why we did that at the first place, so I hope removing doesn't break anything.

I'm still going to try basic processes (CRUDing a virtual host, running jobs, some Katello-related stuff, oscap, etc) to verify PRs after everything open is green.

Without this patch Ansible-related scopes for Host::Managed.includes()
would look like:
[ { host_ansible_roles: :ansible_roles }, { ansible_role: [{ ansible_variables:
[:lookup_values] }] } ], which for some reason worked before Rails 7.
After this patch, it looks like:
[ { host_ansible_roles: { ansible_role: [{ ansible_variables:
[:lookup_values] }] } } ].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants