-
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
Vm rollup defaults (ruby solution) #14478
Conversation
@kbrock as I have stated in private previously, I am not a big fan of changing the "default default behavior" since we are already using it in other places and this might cause issues relying on that previous behavior. What I would prefer to see is either:
virtual_delegate :allocated_disk_storage, :used_disk_storage, :provisioned_storage,
:to => :hardware, :allow_nil => true, :default => 0, :uses => {:hardware => :disks},
:use_default_for_nil_sql => true
# lib/extensions/ar_virtual.rb
method_def = <<-METHOD
def #{method_name}(#{definition})
- return self[:#{method_name}] if has_attribute?(:#{method_name})
+ return self[:#{method_name}]#{default if use_default_for_nil_sql} if has_attribute?(:#{method_name})
_ = #{to}
if !_.nil? || nil.respond_to?(:#{method})
_.#{method}(#{definition})
end#{default}
end
METHOD The latter makes it so the default behavior is explicit to the user of both the person assigning or modifying the |
The sql is still bringing back nil. The getter is converting to the default value.
Introduced by ManageIQ#14285 Addresses ManageIQ#14393 A null hardware record was returning null provisioned_storage it is now returning 0 This was causing issues for automate
3f7aa10
to
0071a20
Compare
Checked commits kbrock/manageiq@9dd7669~...0071a20 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
I compared the current I believe that the current code on What @NickLaMuro said is totally true. The recently written code may assume that the attributes will return a I just feel it is less risky to change the way |
Here is the reference to the diffs: https://gist.github.com/kbrock/c08919f7ec51fd7d399bc6f237462804 I think they speak for themselves and make this a no brainer. To mitigate the risk Nick mentioned, I'm going through the references to all these variables and looking for any code like |
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.
Thanks @NickLaMuro for you comments and @kbrock for putting together the gist backing up the explanation for the change. I'm comfortable with this change 👍
Fixes #14393 [Alternate to #14448 ]
Introduced by #14285, the default value for
Vm#provisioned_storage
became nil when there is no hardware record. This PR changes the default back to 0.Details
When delegating a column to another model, and the other model does not exist in the database, the SQL for the attribute comes back as a null. So the attribute looks like it is coming back from SQL, but in truth, it is just a null. Since there is no value, the default needs to be returned.