Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Instance path of properties with ~ in their name might not be correct #788

@DanielNoord

Description

@DanielNoord

This is an issue we're running into with the Python wrapper. I haven't been able to see where the issue is Python/Rust/??? but I did create this minimal reproducer:

from importlib.metadata import version
from jsonschema_rs import Draft202012Validator

data = {
    "table-node": [
        {"~": ""},
        {"other-value": ""},
    ],
}

schema = {
    "type": "object",
    "properties": {
        "table-node": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {"~": {"type": "string", "minLength": 1}},
                "required": ["~"],
            },
        },
    },
    "$schema": "https://json-schema.org/draft/2020-12/schema",
}

validator = Draft202012Validator(schema)

for error in validator.iter_errors(data):
    print(error.instance_path, error.message)

print(version("jsonschema_rs"))

This prints:

['table-node', 0, '~0'] "" is shorter than 1 character
['table-node', 1] "~" is a required property
0.32.1

As you can see the instance_path reported for the minLength error adds a 0 to the ~ of the path. This is unfortunate as therefore you can't connect the error to the data that was being submitted.

I added the other error to show that it is not happening for all transformations of ~ but (for now) seems to only affect the instance path.

As seen in the reproducer, this is with the latest version on PyPI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions