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

automatically clone child element if the child already has a parent #186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rl-utility-man
Copy link

@rl-utility-man rl-utility-man commented Jan 21, 2025

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

temporary_object.add_child(myElement)
final_object.add_child(myElement)
myElement.change(color="red")

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.

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.

1 participant