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

Allow JSON serialization to work with json.dumps #655

Merged
merged 3 commits into from
Jan 9, 2023
Merged

Conversation

hoxbro
Copy link
Member

@hoxbro hoxbro commented Oct 25, 2022

Fixes #578

The changes in #582 made it possible to round-trip serialize <-> deserialize within param.

A completely valid way to deserialize is to have the serialized values created outside param like this:

import json
import param

class User(param.Parameterized):
    A = param.Date(default=None)

data = json.dumps({"A": None})    # gives: '{"A": null}' <- note that null is not a string
User.param.deserialize_parameters(data)

Which raised this error before these changes:

Traceback (most recent call last):
  File "/home/shh/miniconda3/envs/holoviz/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3378, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "/tmp/ipykernel_70470/342607310.py", line 8, in <module>
    User.param.deserialize_parameters(data)
  File "/home/shh/Development/holoviz/repos/param/param/parameterized.py", line 2121, in deserialize_parameters
    return serializer.deserialize_parameters(self_or_cls, serialization, subset=subset)
  File "/home/shh/Development/holoviz/repos/param/param/serializer.py", line 113, in deserialize_parameters
    deserialized = pobj.param[name].deserialize(value)
  File "/home/shh/Development/holoviz/repos/param/param/__init__.py", line 1954, in deserialize
    return dt.datetime.strptime(value, "%Y-%m-%dT%H:%M:%S.%f")
TypeError: strptime() argument 1 must be str, not None

@hoxbro hoxbro requested a review from jlstevens October 25, 2022 08:53
@philippjfr
Copy link
Member

@hoxbro Your fixes here look good, the issue I noted above precede you. So to finish this I'd like to ask you to change all serialize implementations to return None if the value is None and for all deserialize implementations to handle None as input.

@droumis droumis added this to the v1.12.x milestone Jan 9, 2023
@philippjfr
Copy link
Member

Okay, sorry again. I think you already did that. Sorry for the noise.

@philippjfr philippjfr merged commit 5b39ef3 into main Jan 9, 2023
@philippjfr philippjfr deleted the date_allow_none2 branch January 9, 2023 17:12
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.

Serializing Date parameters does not support allow_None
3 participants