Skip to content

Change upload value to contain Python types #2767

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

Merged

Conversation

pbugnion
Copy link
Member

@pbugnion pbugnion commented Feb 2, 2020

Prior to this PR, the .value traitlet for the FileUpload widget was a list of dictionaries. Each dictionary contained the raw metadata generated by the browser, as well as the content as a memoryview.

This PR changes the return value to be a tuple of Bunch instances. Attribute names inside the bunch are converted to snake case and the last modified is converted to a zoned datetime.

For instance:

# f is a FileUpload instance
>>> f.value
({'name': 'some-name.png',
  'type': 'image/png',
  'size': 29841,
  'content': <memory at 0x118001940>,
  'last_modified': 1578491179205},)

This PR also removes syncing an 'error' attribute per file. This was not exposed in the kernel, and it was never set to anything apart from an empty string in the frontend. Note that the global error attribute remains.

Note that this PR has some overlap with #2715 : both share datetime serialization / deserialization considerations. In here, I have done the least amount of work -- I just send a timestamp over the wire, and manage conversion in the kernel. Once 2548 is merged, it may be worth overhauling serialization to have a common interface. That won't be a breaking change.

Closes issue #2727 .

@pbugnion pbugnion changed the title Change upload value to contain Python types [WIP] Change upload value to contain Python types Feb 2, 2020
@pbugnion pbugnion force-pushed the upload-value-as-python-types branch from c5b5609 to ddc9b33 Compare February 2, 2020 17:07
@pbugnion pbugnion changed the title [WIP] Change upload value to contain Python types Change upload value to contain Python types Feb 2, 2020
@pbugnion pbugnion marked this pull request as ready for review February 2, 2020 17:13
@pbugnion
Copy link
Member Author

pbugnion commented Feb 2, 2020

This is now ready for review.

@jasongrout jasongrout added this to the 8.0 milestone Feb 5, 2020
js = {}
for attribute in ['name', 'type', 'size', 'content']:
js[attribute] = uploaded_file[attribute]
js['lastModified'] = int(uploaded_file['last_modified'].timestamp() * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our general convention, at least in default controls, has been snake_case for the attributes in the protocol messages. Should we keep it snake_case here, as last_modified?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to just call it modified, or even mtime, which mirrors the stat() structure and how you address it in python and presumably lots of other languages that let you make a stat call.

Copy link
Member Author

@pbugnion pbugnion Feb 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mtime in Python is a timestamp, whereas we're returning a datetime. That warrants using a different name, I think.

I'll go withlast_modified, but this is not strongly held (so feel free to change it).

@jasongrout
Copy link
Member

This looks great! A couple of inline comments above, and then I think it's ready to go.

@pbugnion
Copy link
Member Author

Thanks for the feedback. I made all the changes discussed.

@jasongrout
Copy link
Member

Thanks! This looks really great.

@jasongrout jasongrout merged commit 1d8f7b0 into jupyter-widgets:master Feb 12, 2020
@pbugnion pbugnion deleted the upload-value-as-python-types branch February 13, 2020 07:34
@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
backwards-incompatible 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.

2 participants