Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Serialization of None is now very inconsistent #140

Open
damz opened this issue Sep 4, 2013 · 2 comments
Open

Serialization of None is now very inconsistent #140

damz opened this issue Sep 4, 2013 · 2 comments

Comments

@damz
Copy link

damz commented Sep 4, 2013

The serialization of None is very inconsistent since 1.0b1, because #513d860 reverted part of the special cases for None:

  • String: "None"
  • Boolean: False
  • Date, Time, DateTime: null
  • Integer, Float, Decimal, Money: error
  • GlobalObject: error
  • Mapping, Tuple, Sequence: error
  • Set, List: None

In our schemas, we have definitions like:

result = SchemaNode(String(),
    title="Result",
    validator=OneOf([ None, "success", "failure" ]), missing=None,
)

(ie. result can be undefined, "success" or "failure") that are broken because None is now serialized to "None" instead of passing through as null

Any idea how to move forward from here, and what is the correct behavior?

@mrijken
Copy link
Contributor

mrijken commented Sep 4, 2013

I fully agree. In my opinion the type of the deserialized value needs
always be the same as the type described in the node. So a
SchemaNode(String()) needs always be deserialized to a string.
SchemaNode(Boolean()) needs always be deserialized to False or True. If
deserialization to the given type (string or boolean in the example) is not
possible, null will be the value. The same applies to all other types. So a
missing value which is not of the given type should also not be possible.

If you want to have None as a possible value, the node needs to describe
that explicit with a type which can be deserialized to None. I have made a
possible implementation of a NoneType, which can be used in addition to
other types. See #121.

2013/9/4 Damien Tournoud notifications@github.com

The serialization of None is very inconsistent since 1.0b1, because
#513d860 reverted part of the special cases for None:

  • String: "None"
  • Boolean: False
  • Date, Time, DateTime: null
  • Integer, Float, Decimal, Money: error
  • GlobalObject: error
  • Mapping, Tuple, Sequence: error
  • Set, List: None

In our schemas, we have definitions like:

result = SchemaNode(String(),
title="Result",
validator=OneOf([ None, "success", "failure" ]), missing=None,
)

(ie. result can be undefined, "success" or "failure") that are broken
because None is now serialized to "None" instead of passing through as
null

Any idea how to move forward from here, and what is the correct behavior?


Reply to this email directly or view it on GitHubhttps://github.com//issues/140
.

@hathawsh
Copy link
Member

hathawsh commented Dec 8, 2013

I'm stuck at 1.0a5 because of this. :-( In most (perhaps all) cases, it seems like None should be serialized the same way as null. That way, colander.null doesn't leak into apps; only code that customizes Colander (validators, widgets, SchemaNode extensions, etc.) has to deal with colander.null.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants