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
Refs #33470 - ensure OS.minor is not nil #9075
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class EnsureOsMinorIsNotNil < ActiveRecord::Migration[6.0] | ||
def up | ||
User.without_auditing do | ||
Operatingsystem.unscoped.find_each do |os| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we filter with And I think the DB should be modified to have a NOT NULL, possibly also a DEFAULT empty string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surprise! We already have the default and NOT NULL in the db, at least this is what I see in my dump:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah this was implemented some time ago: https://projects.theforeman.org/issues/297 |
||
unless os.minor | ||
os.minor = '' | ||
os.save(validate: false) | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think changing
\.
to.
is correct. If it is, you change it to/[^.]/
or essentially.
so it will always drop the character.Funny thing: the git blame for this line is 1387528 and it speaks about
minor
beingnil
instead of""
. I vaguely recall thatnil.to_s
returns an empty string instead ofnil
. We probably rely on this Ruby behavior to ensure non-null entries.That means this code is not the offender, right?
The problem does not show up with vanilla Foreman, only with Katello. Perhaps this is coming from the RHSM fact parser? However, that has this code:
foreman/app/services/katello/rhsm_fact_parser.rb
Line 60 in c693cd9
I would think the
|| ''
would take care of it.So I'm not entirely sure where this comes from. I'll see if I can spin up a pipeline for a reproducer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said in https://community.theforeman.org/t/katello-nightly-rpm-pipeline-1220-failed/27082/11: currently nightly is passed and I can no longer find a reproducer. That makes it very hard to review this. However, since
nil.to_s
is already""
, the|| ''
part will never be triggered and I think it can be left out.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was recommended by me by Rubocop: https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RedundantRegexpEscape
What is your concern? I don't understand.
Well since we are at it and the code with
to_s
really smells, let's try to ensure there are no nil values via the migration and constraint rule? In the worst case, well, we break this. Not for the first time or last...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I didn't think it was redundant.
I'm worried it'll be the catchall
.
instead of a literal.
. However, testing suggests it is indeed the literal.
:I must say I really dislike regexes and all these subtle nuances.