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

Add preparer for serialize #329

Open
digitalresistor opened this issue Feb 26, 2019 · 0 comments
Open

Add preparer for serialize #329

digitalresistor opened this issue Feb 26, 2019 · 0 comments

Comments

@digitalresistor
Copy link
Member

Currently when you serialize values, there is no preparer step before passing it off to the sub-types (in the case of the MappingSchema)

colander/colander/__init__.py

Lines 2276 to 2293 in 141263a

def serialize(self, appstruct=null):
""" Serialize the :term:`appstruct` to a :term:`cstruct` based
on the schema represented by this node and return the
cstruct.
If ``appstruct`` is :attr:`colander.null`, return the
serialized value of this node's ``default`` attribute (by
default, the serialization of :attr:`colander.null`).
If an ``appstruct`` argument is not explicitly provided, it
defaults to :attr:`colander.null`.
"""
if appstruct is null:
appstruct = self.default
if isinstance(appstruct, deferred): # unbound schema with deferreds
appstruct = null
cstruct = self.typ.serialize(self, appstruct)
return cstruct

this means we can not influence the appstruct before passing it off to the various subtypes in the mapping schema

https://github.com/Pylons/colander/blob/master/colander/__init__.py#L811-L818

This doesn't match the deserialize API which has a preparer function that can be used to modify the cstruct before passing to children and or validation.

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

No branches or pull requests

1 participant