-
Notifications
You must be signed in to change notification settings - Fork 145
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
Contrary to the documentation, 'default' affects #262
Comments
does any of #237 help? |
Not sure what you mean by "help". :-) I believe the original design of colander (as extensively documented!) is reasonable and correct. I also believe that using I was able to find a workaround—not based on Here's a fix I was considering but didn't try. |
Yeah, that does seem like a bug. I'm curious if any of the existing tests
|
Colander has a page devoted to describing Colander's use of Null and Drop values. The product's current behaviour doesn't match that description. Specifically,
default
should only affect serialization—but it currently affects deserialization too, ifdefault
is set tocolander.drop
.Consider this code:
It produces:
That's exactly what we expect:
'hair_color'
wasn't passed in, so during serialization we got the default value and during deserialization we got the missing value.Now let's change
default
tocolander.drop
:It produces:
hair_color
was dropped during serialization—but it was also dropped during deserialization. We should have gotten themissing
value instead.The problem seems to be that
Mapping.serialize()
andMapping.deserialize()
both callMapping._impl()
, andMapping._impl()
consultsdefault
. There's a similar problem inSequence
:Sequence.serialize()
andSequence.deserialize()
both callSequence._impl()
, andSequence._impl()
consultsdefault
. Deserialization should never consultdefault
.At least where mappings are concerned, this is a very old bug. It was introduced in this commit in 2014. That commit was an attempt to fix this bug. That bug actually describes what I'm trying to do: have a
default
value ofcolander.drop
and amissing
value ofNone
. (TheSequence
bug was introduced in this commit which appears to have copied theMapping
code.)My current workaround is to use
deferred()
andbind()
to instantiate one variation of the schema for serialization and another one for deserialization.The text was updated successfully, but these errors were encountered: