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

prefer class attribute over cattr_accessor in miq_policy #20790

Merged
merged 1 commit into from
Nov 9, 2020

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Nov 8, 2020

since cattr_accessors are potentially problematic re: wandering class vars, I think this should also probably be a class attribute

I'm not overly concerned with this one exhibiting the problematic behavior, however, because of the work done on #20274 this caught my eye because of Jason's #20664 (comment). as a general rule we probably shouldn't be using cattr_accessor.

see #20785, in which the same change was made, for the same reason, with the same level of concern

@miq-bot
Copy link
Member

miq-bot commented Nov 8, 2020

Checked commit d-m-u@080e97b with ruby 2.6.3, rubocop 0.82.0, haml-lint 0.35.0, and yamllint
1 file checked, 0 offenses detected
Everything looks fine. 👍

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

So I’m guessing the @@ and cattr are breaking down due to the shared parent class but I’m not fully there. I’m typically pretty confident when it comes to classes/singleton classes and class variables so I’m in an uncomfortable and unfamiliar place. Could you share more info about the construct and why you feel we are not breaking something and what we hope to gain?

Thnx Drew

@@ -51,7 +51,7 @@ class MiqPolicy < ApplicationRecord

attr_accessor :reserved

cattr_accessor :associations_to_get_policies
class_attribute :associations_to_get_policies

@@built_in_policies = nil
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to change too? This is a cattr.

@@ -51,7 +51,7 @@ class MiqPolicy < ApplicationRecord

attr_accessor :reserved

cattr_accessor :associations_to_get_policies
class_attribute :associations_to_get_policies
Copy link
Member

Choose a reason for hiding this comment

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

The use of self To clarify the variable had me confused. Also the << not seeming to work but += did (for arrays). Could you explain the issue before and why we are not concerned with introducing bugs here?

@kbrock
Copy link
Member

kbrock commented Nov 9, 2020

thanks for the education.
I'm all good with these changes

@kbrock kbrock merged commit 9d88284 into ManageIQ:master Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants