Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.

Conversation

@mdboom
Copy link
Contributor

@mdboom mdboom commented Feb 5, 2018

When there is no c.NotebookGist.oauth_client_id in jupyter_notebook_config.py,
self.config.NotebookGist.oauth_client_id is a lazy value, which can't be
serialized to JSON. This crashes the writing of notebook.json by Jupyter,
and corrupts the notebook.json file. This fix makes sure that value is a
string, otherwise it just sets it to None. When None, the frontend will
helpfully warn (as it always has) that the user hasn't set up their oauth ids.

r? @jezdez

@mdboom
Copy link
Contributor Author

mdboom commented Feb 5, 2018

Also see related change to make this kind of thing less severe on the notebook side: jupyter/notebook#3305

Adds Python 3.6, drops Python 3.3

Fixes version conflict around flake8

Adds tornado (which wasn't getting installed automatically into pypy)

Use different Travis Python environments
@mdboom mdboom force-pushed the fix-oath-client-id branch from 6907c2f to 0d28456 Compare February 5, 2018 23:28
@codecov-io
Copy link

codecov-io commented Feb 5, 2018

Codecov Report

Merging #57 into master will decrease coverage by 1.92%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
- Coverage   63.33%   61.41%   -1.93%     
==========================================
  Files           3        3              
  Lines         180      184       +4     
  Branches       25       26       +1     
==========================================
- Hits          114      113       -1     
- Misses         64       68       +4     
- Partials        2        3       +1
Impacted Files Coverage Δ
src/jupyter_notebook_gist/config.py 53.84% <25%> (-12.83%) ⬇️
src/jupyter_notebook_gist/handlers.py 63.29% <0%> (-1.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 61f083e...0ff0389. Read the comment docs.

@mdboom mdboom force-pushed the fix-oath-client-id branch from e4f9345 to 0d28456 Compare February 6, 2018 18:44
…auth_client_id

When there is no `c.NotebookGist.oauth_client_id` in jupyter_notebook_config.py,
`self.config.NotebookGist.oauth_client_id` is a lazy value, which can't be
serialized to JSON.  This crashes the writing of `notebook.json` by Jupyter,
and corrupts the `notebook.json` file.  This fix makes sure that value is a
string, otherwise it just sets it to `None`.  When `None`, the frontend will
helpfully warn (as it always has) that the user hasn't set up their oauth ids.
@mdboom mdboom force-pushed the fix-oath-client-id branch from 0d28456 to c175659 Compare February 6, 2018 18:50
Copy link
Contributor

@jezdez jezdez left a comment

Choose a reason for hiding this comment

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

rwc+

# update the frontend settings with the currently passed
# OAUTH client id
client_id = self.config.NotebookGist.oauth_client_id
if not isinstance(client_id, (str, bytes)):
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work in case the client id is a unicode value on Python 2.x (since str == bytes there) and fail with a hard to catch thing. The typical solution is to use basestring on 2.x but that's gone on 3.x. We could use six for this, but I guess that seems like a lot of code to rely on just for this silly thing, so lets do something like this here instead. You could also add it to a _compat.py or something.

# ...

try:
    basestring
except NameError:
    basestring = str

# ...

if not isinstance(client_id, basestring):
    # ...

Of course the real fix is to stop supporting Python 2.x. 🤡

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. Of course, six is a dependency of Jupyter notebook, and this package of course makes no sense without the notebook, so I think it's safe to rely on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point! That means we'll have to list it explicitly in the setup.py install_requires list though, just in case notebook ever stops using six for compatibility.

@mdboom mdboom force-pushed the fix-oath-client-id branch from 091ef48 to f4abd1b Compare February 6, 2018 22:43
@mdboom mdboom force-pushed the fix-oath-client-id branch from f4abd1b to 0d2816e Compare February 6, 2018 22:51
@jezdez jezdez merged commit 7801247 into mozilla:master Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants