Skip to content

Data send multiple times to backend #1195

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

Closed
maartenbreddels opened this issue Mar 12, 2017 · 5 comments · Fixed by #1298
Closed

Data send multiple times to backend #1195

maartenbreddels opened this issue Mar 12, 2017 · 5 comments · Fixed by #1298
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Milestone

Comments

@maartenbreddels
Copy link
Member

While working on #1194, I noticed what I think is a bug. Take the following code:

import ipywidgets
s = ipywidgets.IntSlider(description="hello", min=0, max=2, value=0)
v = ipywidgets.IntText(value=1)
ipywidgets.jslink((v, 'value'), (s, 'value'))
ipywidgets.HBox([s,v])

Now in a next cell, you execute:

s.description = "world"

All is fine, the js logic with state_lock will avoid that this gets send to the python backend again, however, in the js side, s.model.change still recorded that description was changed. If you now enter a digit in the IntText, it will trigger a save_changes in the IntSlider, and it will again send {description: 'world', ..} to the backend. This happens in many other cases. For instance, in my case, this is an array with a ~million entries, not something you'd like to send around multiple times.
I am not sure how to resolve this, although happy to try.

PS: Is there any way to get a reference to a widgets in the js console, in ipyvolume is just set window.last_scatter = this; for debugging, but maybe there is a general way.

@maartenbreddels
Copy link
Member Author

Looking at the source (also of backbone), I suggest changing WidgetModel.set_state, it should remove all key/values from self.changed (after this.set(..)) is called, for which the value didn't change by a change listener that was called by this.set. This follows the same logic as in WidgetModel.sync. For instance state was before {'x': 1, 'y':2}, and say that when x is changed, in the 'change-listener' y is set to 3, 'x' should be removed from this.changes. This may feel uncomfortable poking around in backbonejs' internals, but I don't think backbone can handle this case.

@maartenbreddels
Copy link
Member Author

maartenbreddels commented Mar 12, 2017

Actually, changed will be reset on the next .set, it appears that _buffered_state_diff is the guilty one.

@maartenbreddels
Copy link
Member Author

@jasongrout I've demonstated the bug here
For some reason, 'y' enters in last_doubler._buffered_state_diff, since you're working on this now, you may see where it goes wrong. Also included a screenshot.
screen shot 2017-04-12 at 21 17 52

@jasongrout
Copy link
Member

jasongrout commented Apr 18, 2017

In your doubler example, you'll want to use this.save_changes(), not this.save(). The save_changes function automatically syncs the attributes that have changed since the last time we synced.

@maartenbreddels
Copy link
Member Author

👍 confirmed that works.

@github-actions github-actions bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label Feb 13, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
2 participants