-
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
Fix "Multiple Parents Found" issue when moving a relationship. #14060
Conversation
@Fryguy tests are red. Can you describe what this PR is fixing? It's not clear how this fixes the multiple parents found problem? |
0eaa28f
to
7cde7e9
Compare
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. |
7cde7e9
to
b9dd9b5
Compare
alias_method :set_child, :add_children | ||
|
||
def replace_parent(parent) | ||
def parent=(parent) |
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.
but now this method does not use the parameter parent
??
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.
what? it does...not sure what you mean.
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.
my bad. was reading GitHub diffs incorrectly.
b9dd9b5
to
652bfa7
Compare
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
652bfa7
to
af9e051
Compare
Some comments on commit Fryguy@af9e051 spec/models/mixins/relationship_mixin_spec.rb
|
Checked commit Fryguy@af9e051 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 app/models/mixins/relationship_mixin.rb
|
I fixed the tests passing, but I think I need to comb the code for all uses of |
@@ -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) } |
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.
Am I reading this correctly that these two places are the only ones where we want might want to have multiple children/parents?
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.
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=
. 😢
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.
Yeah, those are some of the intentional "multiple parents", so having a method that is specifically designed for that seems clearer.
@jrafanie I checked the whole code base for parent=, set_parent, replace_parent, and :parent =>, and I everything looks good. |
@Fryguy can you mark euwe/darga labels? |
Fix "Multiple Parents Found" issue when moving a relationship. (cherry picked from commit 31a42b7) 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
Euwe backport details:
|
Fix "Multiple Parents Found" issue when moving a relationship. (cherry picked from commit 31a42b7) https://bugzilla.redhat.com/show_bug.cgi?id=1428079
Originally,
.parent=
was written in terms ofadd_children
. However,add_children
supports duplicating nodes in the tree. This is reasonablebecause you may have a tree where multiple entries make sense, and for
those things that have multiple entries, you wouldn't call
.parent
, youwould 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 tocall
.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