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

Fix "Multiple Parents Found" issue when moving a relationship. #14060

Merged
merged 1 commit into from
Mar 1, 2017

Conversation

Fryguy
Copy link
Member

@Fryguy Fryguy commented Feb 24, 2017

Originally, .parent= was written in terms of add_children. However,
add_children supports duplicating nodes in the tree. This is reasonable
because you may have a tree where multiple entries make sense, and for
those things that have multiple entries, you wouldn't call .parent, you
would probably call .parents and it is expected that calling .parent
would blow up with the "Multiple Parents Found" error. However, the
expectation of calling .parent= is that it will become the new, sole,
parent, and so implementing it via add_children is wrong because it
creates an oddity in that you can call .parent= and then not be able to
call .parent afterwards.

https://bugzilla.redhat.com/show_bug.cgi?id=1379464
https://bugzilla.redhat.com/show_bug.cgi?id=1391850
https://bugzilla.redhat.com/show_bug.cgi?id=1406431

@jrafanie
Copy link
Member

@Fryguy tests are red. Can you describe what this PR is fixing? It's not clear how this fixes the multiple parents found problem?

@Fryguy Fryguy force-pushed the die_multiple_parents_found branch from 0eaa28f to 7cde7e9 Compare February 24, 2017 17:39
@Fryguy
Copy link
Member Author

Fryguy commented Feb 24, 2017

Updated the OP and commit with a better description. I had thought the tests were self-explanatory, but I agree this needed to be made clearer.

@Fryguy Fryguy force-pushed the die_multiple_parents_found branch from 7cde7e9 to b9dd9b5 Compare February 24, 2017 17:42
alias_method :set_child, :add_children

def replace_parent(parent)
def parent=(parent)
Copy link
Member

Choose a reason for hiding this comment

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

but now this method does not use the parameter parent??

Copy link
Member Author

Choose a reason for hiding this comment

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

what? it does...not sure what you mean.

Copy link
Member

Choose a reason for hiding this comment

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

my bad. was reading GitHub diffs incorrectly.

@Fryguy Fryguy force-pushed the die_multiple_parents_found branch from b9dd9b5 to 652bfa7 Compare February 24, 2017 22:06
Originally, `.parent=` was written in terms of `add_children`.  However,
`add_children` supports duplicating nodes in the tree.  This is reasonable
because you may have a tree where multiple entries make sense, and for
those things that have multiple entries, you wouldn't call `.parent`, you
would probably call `.parents` and it is expected that calling `.parent`
would blow up with the "Multiple Parents Found" error.  However, the
expectation of calling `.parent=` is that it will become the new, sole,
parent, and so implementing it via add_children is wrong because it
creates an oddity in that you can call `.parent=` and then not be able to
call `.parent` afterwards.

https://bugzilla.redhat.com/show_bug.cgi?id=1379464
https://bugzilla.redhat.com/show_bug.cgi?id=1391850
https://bugzilla.redhat.com/show_bug.cgi?id=1406431
@Fryguy Fryguy force-pushed the die_multiple_parents_found branch from 652bfa7 to af9e051 Compare February 24, 2017 22:07
@miq-bot
Copy link
Member

miq-bot commented Feb 24, 2017

Some comments on commit Fryguy@af9e051

spec/models/mixins/relationship_mixin_spec.rb

  • ⚠️ - 204 - Detected puts. Remove all debugging statements.
  • ⚠️ - 233 - Detected puts. Remove all debugging statements.

@miq-bot
Copy link
Member

miq-bot commented Feb 24, 2017

Checked commit Fryguy@af9e051 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
4 files checked, 3 offenses detected

app/models/mixins/relationship_mixin.rb

@Fryguy
Copy link
Member Author

Fryguy commented Feb 24, 2017

I fixed the tests passing, but I think I need to comb the code for all uses of parent= (and set_parent alias) to make sure that untested code still will work as expected. Luckily the tests in account and miq_widget_set (which were effectively testing miq_set) covered some fixes.

@@ -120,7 +120,7 @@ def groups
end

def add_group(owner)
with_valid_account_type('user') { set_parent(owner) }
with_valid_account_type('user') { add_parent(owner) }
Copy link
Member

Choose a reason for hiding this comment

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

Am I reading this correctly that these two places are the only ones where we want might want to have multiple children/parents?

Copy link
Member

Choose a reason for hiding this comment

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

Doh, I just read the comment above. So anyway, it makes sense, but to your point, there is probably untested code that might need to be changed. It's such a hard regex to find bad uses of parent=. 😢

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, those are some of the intentional "multiple parents", so having a method that is specifically designed for that seems clearer.

@Fryguy
Copy link
Member Author

Fryguy commented Mar 1, 2017

@jrafanie I checked the whole code base for parent=, set_parent, replace_parent, and :parent =>, and I everything looks good.

@jrafanie jrafanie merged commit 31a42b7 into ManageIQ:master Mar 1, 2017
@jrafanie jrafanie added this to the Sprint 56 Ending Mar 13, 2017 milestone Mar 1, 2017
@jrafanie
Copy link
Member

jrafanie commented Mar 1, 2017

@Fryguy can you mark euwe/darga labels?

@Fryguy Fryguy deleted the die_multiple_parents_found branch March 1, 2017 18:39
@simaishi
Copy link
Contributor

simaishi commented Mar 9, 2017

Euwe backport details:

$ git log -1
commit b88ad85327212c315d7a3a1c528ec665475ef171
Author: Joe Rafaniello <[email protected]>
Date:   Wed Mar 1 13:38:06 2017 -0500

    Merge pull request #14060 from Fryguy/die_multiple_parents_found
    
    Fix "Multiple Parents Found" issue when moving a relationship.
    (cherry picked from commit 31a42b746f97772c7af10a322d44de3e4fbd7eca)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1428079
    https://bugzilla.redhat.com/show_bug.cgi?id=1428126
    https://bugzilla.redhat.com/show_bug.cgi?id=1428124

agrare pushed a commit to agrare/manageiq that referenced this pull request Apr 19, 2017
Fix "Multiple Parents Found" issue when moving a relationship.
(cherry picked from commit 31a42b7)

https://bugzilla.redhat.com/show_bug.cgi?id=1428079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants