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 progress serialization issue #381

Merged
merged 4 commits into from
Nov 29, 2019

Conversation

consideRatio
Copy link
Member

This fixes what was reported in z2jh, where the hub doesn't crash but
fails to render the progress properly when it is serializing the events
and passing them to the browser to render them.

The error we got then was:

```
    TypeError: Object of type 'V1Event' is not JSON serializable
```

I think it makes best sense to not require jupyterhub to know about the
structure of the content and downstream make this serializable, but
instead reaquire all things to be serializable.

ref: jupyterhub/zero-to-jupyterhub-k8s#1501
@betatim
Copy link
Member

betatim commented Nov 29, 2019

In some other projects I use something like the following to serialise datetime objects (this is whats failing/why travis is unhappy):

import json

class JSONEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, datetime.datetime):
            return obj.isoformat()
        return super().default(obj)
json._default_encoder = JSONEncoder()

but I am not sure this is "the right way" of doing this.

Reading https://code-maven.com/serialize-datetime-object-as-json-in-python which you linked in jupyterhub/zero-to-jupyterhub-k8s#1501 (comment) looks like the better option of doing the same.

What I don't know how to do is how to pass the default argument because the serialisation happens somewhere deep inside :-/

@manics
Copy link
Member

manics commented Nov 29, 2019

What uses the raw-event? Would a combination of event.to_dict() and converting the datetime field to an iso8601 string (.isoformat()) work?

@consideRatio
Copy link
Member Author

@clkao added it with a motivation that makes sense to me generally in #361.

@manics
Copy link
Member

manics commented Nov 29, 2019

v = kubernetes.client.models.V1Event(involved_object={}, metadata={}, event_time=datetime.datetime.now())
d = v.to_dict()
for (k, v) in d.items():
    if isinstance(v, datetime.datetime):
        d[k] = v.isoformat()

@consideRatio
Copy link
Member Author

manics you have the series field of the event object that van have datetimes in it as well (MicroTime ins the k8s api ref). So it must go deeper if we do this.

@consideRatio consideRatio merged commit 8636fda into jupyterhub:master Nov 29, 2019
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.

Spawner event stream malfunctions :/
3 participants