colander icon indicating copy to clipboard operation
colander copied to clipboard

Number cannot serialize None and Datetime serializes None to colander.null

Open ny2ko opened this issue 9 years ago • 3 comments

I would like to know why Int (Number generally) cannot deserialize None i.e. serialize None to None. This used to be the case in previous versions of colander but it seems to have been removed. Instead now it fails on the call to int(None). Was there a reason for this design change?

Also DateTime serializes None to colander.null. This has been changed for most other types to only serialized colander.null to colander.null by:

def serialize(self, node, appstruct):
        if appstruct is null:
            return null

Is there a reason why DateTime is any different?

ny2ko avatar Aug 27 '14 23:08 ny2ko

@ny2ko I'd rather have number type always give me a number, and not None. Think static typing. The only case where I'd want None to be converted to None would be when I explicitly specify missing to None.

</ Personal Opinion>

jaseemabid avatar Dec 17 '14 10:12 jaseemabid

I'm confused too... It seems the Number functionality was reverted in 513d8600431a2680e3a1d781eafc0cc51243dafa but I can't seem to see any comments as to why the change was made. @mcdonc since you committed that, can you comment on this? The previous behaviour was to treat both None and colander.null as colander.null. This seems to make sense with respect to the null documentation saying the purpose of colander.null is to represent a non-value in the cases where None is a valid value. If we're in a case where None isn't valid (as is the case for Numbers) why not make it work the same as colander.null?

tisdall avatar Jan 29 '15 18:01 tisdall

related to #140

tisdall avatar Jan 29 '15 18:01 tisdall