Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Sequence of simple types does not deserialize unless it has a name #149

Closed
rbu opened this Issue · 3 comments

3 participants

@rbu

Consider the following schema similar to this demo http://deformdemo.repoze.org/sequence_of_constrained_len/

class EmailMessage(colander.Schema):
    subject = colander.SchemaNode(colander.String())
    to = colander.SchemaNode(colander.Sequence(), colander.SchemaNode(colander.String()))

This will correctly serialize and deserialize in colander for an app/cstruct such as

dict(subject='hello', to=['@'])

However, rendering the deform for it will not create a structure that can be read back by deform, because the inner SchemaNode of the sequence has no name. deform will render the following:

deform.Form(schema=EmailMessage()).render(dict(subject='hello', to=['@']))

<input type="hidden" name="__start__" value="to:sequence"...>
<input type="text" name="" value="@" />

A working way to declare the schema is:

class EmailMessage(colander.Schema):
    subject = colander.SchemaNode(colander.String())
    to = colander.SchemaNode(colander.Sequence(), colander.SchemaNode(colander.String(), name="ignored"))

I would argue that deform should either insert a random name if none is given (or needed) or raise an assertion during render if a name is always required. This was a completely unobvious behavior and debugging it took quite a while.

@ppaez ppaez referenced this issue from a commit in ppaez/deform
@ppaez ppaez Fix issue #149
- Raise a ValueError exception when the prototype
  for a field in a sequence has no name.
6673539
@ppaez ppaez referenced this issue from a commit in ppaez/deform
@ppaez ppaez Coverage for the fix for issue #149 bdd9adc
@mcdonc
Owner

Closed via above commits.

@mcdonc mcdonc closed this
@mcdonc
Owner

Thank you @rbu !

@davidjb

This is going to break backwards compatibility for people (eg it did for me) until they update their schemas. For what it's worth, my schema nodes without names were working, but seemingly because they were Mappings/Sequences, which gave a name=":mapping" by default.

Can someone document what needs users need to change somewhere obvious (eg in the documentation / change log), rather than just what's on this ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.