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 Upload widget counter value #2666

Merged
merged 6 commits into from
Jan 8, 2020

Conversation

jtpio
Copy link
Member

@jtpio jtpio commented Jan 6, 2020

Fixes #2480.

It looks like the _counter value was used to detect a change of the value.

Instead we could use data to achieve the same result, since its value should change when new files are being uploaded.

fileupload-counter-fixed

Breaking changes

  • Rename data to _data
  • Rename metadata to _metadata
  • Make _counter, _metadata and _data read-only
  • value is a list of dicts. Example:
[{ 'metadata': {}, 'content': <memoryview>}]

@jtpio jtpio marked this pull request as ready for review January 6, 2020 16:55
@pbugnion
Copy link
Member

pbugnion commented Jan 7, 2020

Thanks for this.

I agree that it's a little strange that we're using _counter both to decide whether there's been an upload event and to update the description.

I'm not sure I agree that switching to observing the data trait solves our problems though. For instance, what happens if someone uploads:

  1. A.txt with content hello
  2. B.txt with content hello

I don't think data changes in this case? (I haven't checked this, so I may well be wrong)

An alternative could be to keep _counter, but not use it in the button label? We could have a new model property (that doesn't necessarily make its way all the way to the Python layer) called fileCount that measures the current number of files?

@jtpio
Copy link
Member Author

jtpio commented Jan 7, 2020

I don't think data changes in this case? (I haven't checked this, so I may well be wrong)

Thanks for raising that point. We should be able to check that behavior.

It looks it's possible for data to not change, but for metadata to change. In that case value would indeed have to be recalculated.

An alternative could be to keep _counter, but not use it in the button label? We could have a new model property (that doesn't necessarily make its way all the way to the Python layer) called fileCount that measures the current number of files?

Right, with the current change _counter is only used in the button label and doesn't need to live in the kernel. We would still need a way to detect a state change to be able to set value accordingly.

Another way could be to compute value on the frontend, and push it back to the kernel? So the _data_changed method would not be needed anymore.

@pbugnion
Copy link
Member

pbugnion commented Jan 7, 2020

It looks it's possible for data to not change, but for metadata to change. In that case value would indeed have to be recalculated.

Thanks for checking.

Right, with the current change _counter is only used in the button label and doesn't need to live in the kernel.

Agreed.

Another way could be to compute value on the frontend, and push it back to the kernel? So the _data_changed method would not be needed anymore.

To me, that sounds like the right call, except data and metadata are annoyingly exposed as public traits in the Python-side. Somewhat weirdly, data and metadata are not read-only. I'm not sure what would happen if someone sets them server-side.

We could break backwards compatibility and just keep value as a read-only trait?

@jtpio
Copy link
Member Author

jtpio commented Jan 7, 2020

We could break backwards compatibility and just keep value as a read-only trait?

It's possible that data and metadata were kept that way to leverage the binary serialization for data, so that the value dict can be computed on the Python side.

@pbugnion
Copy link
Member

pbugnion commented Jan 7, 2020

It's possible that data and metadata were kept that way to leverage the binary serialization for data

Ah yeah, that makes sense. They should probably still be read-only.

@jtpio jtpio changed the title Fix Upload widget counter value [WIP] Fix Upload widget counter value Jan 7, 2020
@jtpio jtpio added the Work in Progress PRs that are not ready to be reviewed/merged. label Jan 7, 2020
@jtpio jtpio force-pushed the upload-counter branch 3 times, most recently from 250fd81 to eef51ec Compare January 7, 2020 17:30
@jtpio
Copy link
Member Author

jtpio commented Jan 7, 2020

Pushed some changes to:

  • make data and metadata private and read only
  • use a client side _file_count for the Upload button view
  • keep _counter as a way to trigger the value update

fileupload-counter2

@jtpio jtpio changed the title [WIP] Fix Upload widget counter value Fix Upload widget counter value Jan 7, 2020
@jtpio jtpio removed the Work in Progress PRs that are not ready to be reviewed/merged. label Jan 7, 2020
@pbugnion
Copy link
Member

pbugnion commented Jan 8, 2020

I think this looks good. I think it'd be useful to discuss with people explicitly removing data and metadata from the public API.

@jtpio jtpio changed the title Fix Upload widget counter value [WIP] Fix Upload widget counter value Jan 8, 2020
@SylvainCorlay SylvainCorlay added this to the 8.0 milestone Jan 8, 2020
@jtpio jtpio force-pushed the upload-counter branch 2 times, most recently from f6fbb8a to bd6c883 Compare January 8, 2020 16:59
@pbugnion pbugnion changed the title [WIP] Fix Upload widget counter value Fix Upload widget counter value Jan 8, 2020
@pbugnion pbugnion merged commit 44fb6f8 into jupyter-widgets:master Jan 8, 2020
@jtpio jtpio deleted the upload-counter branch January 8, 2020 18:42
@jtpio
Copy link
Member Author

jtpio commented Jan 8, 2020

Thanks @pbugnion for adding the comment in 656e2ed.

For reference and to add a bit more context: without this serializer, we indeed hit the default serializer, which performs a deep copy of the value via a JSON.parse / JSON.stringify:

state[k] = JSON.parse(JSON.stringify(state[k]));

This would result in the ArrayBuffer (value of content) being serialized to an empty object ({} ).

@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 20, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg:controls resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FileUpload counter with multiple=False
3 participants