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

josnschema fails when using optional load_default returns MISSING #6

Open
Ragsboss opened this issue Sep 2, 2017 · 0 comments
Open

Comments

@Ragsboss
Copy link

Ragsboss commented Sep 2, 2017

We have a custom type like this

class Optional(lt.Optional):
    def __init__(self, *args, **kwargs):
        if 'load_default' in kwargs:
            kwargs.pop('load_default')

        super(Optional, self).__init__(*args, load_default=s.MISSING, **kwargs)

    def load(self, data, context=None, *args, **kwargs):
        if data is s.MISSING:
            return self.load_default(context)
        elif data is None:
            return data
        return super(Optional, self).load(
            self.inner_type.load(data, context=context, *args, **kwargs),
            *args, **kwargs
        )

With that use following code to see the failure

>>> import lollipop.types as lt
>>> from lollipop_jsonschema import json_schema as lollipop2jsonschema
>>> 
>>> lollipop2jsonschema(lt.Optional(s.String()))
OrderedDict([('type', 'string')])
>>> lollipop2jsonschema(Optional(s.String()))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/lollipop_jsonschema/jsonschema.py", line 140, in json_schema
    js['default'] = schema.inner_type.dump(default)
  File "/usr/local/lib/python2.7/dist-packages/lollipop/types.py", line 212, in dump
    self._fail('required')
  File "/usr/local/lib/python2.7/dist-packages/lollipop/errors.py", line 63, in _fail
    raise ValidationError(msg)
lollipop.errors.ValidationError: Invalid data: 'Value is required'
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