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

JSONSchema Draft 7 array Tuple Validation unsupported? Schema.from_dict() raise exception #145

Open
adrien-mg opened this issue Mar 18, 2021 · 1 comment

Comments

@adrien-mg
Copy link

adrien-mg commented Mar 18, 2021

From the JSON Schema draft 7.0 specification: array types can be used to validate tuple as such:

{
  "type": "array",
  "items": [
    {
      "type": "something"
    },
    {
      "type": "otherthing"
    }
  ]
}

... and as such, the items property of a "type": "array" property can be a python list.

Using the above schema will raise an exception with singer-python==5.1.5 when entering the @singer.utils.handle_top_exception(LOGGER) decorator, although I also can see the error in the master version of the file: https://github.com/singer-io/singer-python/blob/master/singer/schema.py#L107 where the items variable is expected to be a dict (it can also be a list, as stated above)

I think I have a trivial fix which would be to add a isinstance(items, dict) check:

    @classmethod
    def from_dict(cls, data, **schema_defaults):
        '''Initialize a Schema object based on the JSON Schema structure.
        :param schema_defaults: The default values to the Schema
        constructor.'''
        kwargs = schema_defaults.copy()
        properties = data.get('properties')
        items = data.get('items')

        if properties is not None:
            kwargs['properties'] = {
                k: Schema.from_dict(v, **schema_defaults)
                for k, v in properties.items()
            }
        if items is not None and isinstance(items, dict):
            kwargs['items'] = Schema.from_dict(items, **schema_defaults)
        for key in STANDARD_KEYS:
            if key in data:
                kwargs[key] = data[key]
        return Schema(**kwargs)

and I'm happy to raise a PR for it. However I wanted to have the opinion of someone who's closer to the library to know if we even want to support Tuple Validation from the JSON Schema draft 7.0 specifications?

edit: made a bit more readable

@adrien-mg adrien-mg changed the title Schema.from_dict() not respecting array items tuple validation Draft 7 specification JSONSchema Draft 7 array Tuple Validation unsupported? Schema.from_dict() Mar 18, 2021
@adrien-mg adrien-mg changed the title JSONSchema Draft 7 array Tuple Validation unsupported? Schema.from_dict() JSONSchema Draft 7 array Tuple Validation unsupported? Schema.from_dict() raise exception Mar 18, 2021
adrien-mg added a commit to mind-gym/data-tap-mavenlink that referenced this issue Mar 18, 2021
…over file. Removed Tuple Validation from {story,user}_custom_field_values.json schemas as it is currently not supported by the singer-python library, and it will fail when entering the main decorator: @singer.utils.handle_top_exception. Issue was raised at: singer-io/singer-python#145. Also fixed a tiny typo in custom_field_sets.json schema (objects -> object)
@modularTaco
Copy link

I think jsonschema draft7 is fully unsupported, as of

'jsonschema==2.6.0',

and the jsonschema lib in version 2.6.0 only includes the Draft3Validator and Draft4Validator, no validators for draft 5, 6 or 7.

So if there is a specific reason for this jsonschema version, there might be other screws that need to be adjusted for a full draft 7 support.

But i started experimenting with singer-python yesterday, so i may be wrong.

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

2 participants