-
Notifications
You must be signed in to change notification settings - Fork 897
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
Cast virtual attribute 'Hardware#ram_size_in_bytes' to bigint #15554
Cast virtual attribute 'Hardware#ram_size_in_bytes' to bigint #15554
Conversation
app/models/hardware.rb
Outdated
virtual_attribute :ram_size_in_bytes, :integer, :arel => (lambda do |t| | ||
t.grouping(Arel::Nodes::Multiplication.new( | ||
Arel::Nodes::NamedFunction.new("CAST", [t[:memory_mb].as("bigint")]), 1.megabyte)) | ||
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.
Arel... 😱 .... @kbrock @NickLaMuro Can you review this? I have no idea.
@yrudman Can you add a test that recreates the problem? I don't understand how it overflows ram_size_in_bytes
for a single vm in a report. I was under the impression it was a problem aggregating many hardwares for many vm/instances that caused the overflow.
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 seems reasonable to me, as long as the casting is passed on in the multiplication (I think it is, but unsure). I agree with adding a test to confirm this functionality fails in the old code, and works with the new.
This may be my fault from some of the aggregation mixin performance improvements I did a while back, so if it was, I apologize.
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.
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.
@yrudman I would say write a test that creates a hardware record with the same value as what you have in the screenshot you just share, and then try calling the ram_size_in_bytes
method on that record before and after this change. Should break in master and then be fixed with your change.
So, you should just be able to use the console you have open already, and run ActiveRecord::Base.connection.select_values("SELECT MAX(hardwares.memory_mb) FROM hardwares")
to get your out of range value to plug into a spec. The spec should be something simple like this:
describe "#ram_size_in_bytes" do
it "should not cause out of range errors" do
FactoryGirl.create(:hardware, :memory_mb => <<VALUE_YOU_GOT_FROM_THE_CONSOLE_ABOVE>>)
expect{ Hardware.select(:ram_size_in_bytes).all }.to_not raise_error(ActiveRecord::StatementInvalid)
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.
As an alternative solution I have migration PR (not merged) to change datatype of memory_mb
to bigint
and on my test db that column was bigint
. So, I was struggling with providing test which is failing on master ....
a145bf0
to
c98213d
Compare
c98213d
to
92301f3
Compare
92301f3
to
068eb1b
Compare
Checked commits yrudman/manageiq@5231493~...068eb1b with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
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.
Nice! 👍
Cast virtual attribute 'Hardware#ram_size_in_bytes' to bigint (cherry picked from commit a1b007b) https://bugzilla.redhat.com/show_bug.cgi?id=1478565
Fine backport details:
|
…-to-bigint Cast virtual attribute 'Hardware#ram_size_in_bytes' to bigint (cherry picked from commit a1b007b) https://bugzilla.redhat.com/show_bug.cgi?id=1478565
There is
PG::NumericValueOutOfRange
thrown in report onram_size_in_bytes
https://bugzilla.redhat.com/show_bug.cgi?id=1464154
@miq-bot add-label bug, fine/yes
\cc @gtanzillo