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

Preserve $ref history. #1144

Closed

Conversation

atsuoishimoto
Copy link

@atsuoishimoto atsuoishimoto commented Jul 27, 2023

In large schemas, understanding which $ref is being referenced when an error occurs can be helpful in debugging. We used to refer to the history of $ref with code like this:

for error in validator.iter_errors(instance):
    print(validator.resolver._scopes_stack)
    print(error)

However, with the current version of jsonschema, validator.resolver is deprecated, and it will be not possible to refer to it.

In this PR, I have made changes so that the history of $ref is recorded in the exception object when an error occurs, and the $ref from the root to the part where the error occurred can be referred to with error.refs. I believe this feature will be useful not only for us, but for many users as well.

@atsuoishimoto atsuoishimoto temporarily deployed to PyPI July 28, 2023 00:14 — with GitHub Actions Inactive
@atsuoishimoto atsuoishimoto reopened this Jul 28, 2023
@atsuoishimoto atsuoishimoto temporarily deployed to PyPI July 28, 2023 06:55 — with GitHub Actions Inactive
@Julian
Copy link
Member

Julian commented Jul 28, 2023

Your original code clearly touched something private :)

But for this one, I'm willing to consider such a thing, especially given it's required to support #1008, but not precisely in his way.

We'd also need to handle $dynamicRef and $recursiveRef, so some extra thought is needed.

But the objects used within the referencing library were written partially to support this (referencing's Resolver.dynamic_scope essentially contains this information).

I'm going to close this PR given the above but please open an issue and we can discuss some other way to do this.

@atsuoishimoto
Copy link
Author

Thank you for the comment!

I filed the #1146. Thanks!

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

Successfully merging this pull request may close these issues.

None yet

2 participants