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

flatten() AttributeError: '_null' object has no attribute 'get' #206

Open
dmdm opened this issue Feb 16, 2015 · 0 comments
Open

flatten() AttributeError: '_null' object has no attribute 'get' #206

dmdm opened this issue Feb 16, 2015 · 0 comments

Comments

@dmdm
Copy link

dmdm commented Feb 16, 2015

I have a schema with a nested MappingSchema:

class ConfSchema(colander.MappingSchema):
    foo = colander.SchemaNode(colander.Integer())

    @colander.instantiate(missing={})
    class scales(colander.MappingSchema):
        bar = MiniMax()
        baz = MiniMax()

When I flatten an appstruct that has no key 'scales', flatten() throws this exception:

    pprint(sch.flatten(self.mgr.conf))
  File "..../python3.4/site-packages/colander/__init__.py", line 1874, in flatten
    flat = self.typ.flatten(self, appstruct)
  File "..../python3.4/site-packages/colander/__init__.py", line 622, in flatten
    prefix=selfprefix))
  File "..../python3.4/site-packages/colander/__init__.py", line 620, in flatten
    substruct = appstruct.get(name, null)
AttributeError: '_null' object has no attribute 'get'

This patch might help:

    def flatten(self, node, appstruct, prefix='', listitem=False):
        result = {}
        if listitem:
            selfprefix = prefix
        else:
            if node.name:
                selfprefix = '%s%s.' % (prefix, node.name)
            else:
                selfprefix = prefix

        for subnode in node.children:
            # BEGIN PATCH
            if isinstance(appstruct, _null):
                continue
            # END PATCH
            name = subnode.name
            substruct = appstruct.get(name, null)
            result.update(subnode.typ.flatten(subnode, substruct,
                                              prefix=selfprefix))
        return result
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