automatically clone child element if the child already has a parent #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I reported Folium issue 1885, which occurs because passing a single element to the add_child routine twice overwrites the first value of the parent variable inside the element object. @Conengmo suggested adding a clone routine to address this problem, which I have done. Applying add_child(exampleChild) always overwrites the value of the exampleChild.parent variable, which will lead to undesirable behavior, so I changed add_child to always create a clone if the parent variable is not none and use the clone as the child.
This will lead to surprising behavior when you do something like
That code block would likely work in the expected way before this edit. After my edit, myElement.change(color="red") will not change the color of the clone that is the child of final_object.
This is, admittedly, a pretty fundamental fix that has the potential to change behavior in a wide variety of contexts. I'm open to applying this more selectively, but that would leave the likelihood that the same overwriting behavior could cause more problems elsewhere. Thanks for your help. Looking forward to discussing the best way forward.