-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
panic in LazyRefValidator::lazy_compile with jsonschema 0.21 #547
Comments
It seems that the failing schema uses local references like this: {
"$id": "/schemas/base/spatial",
"location": {
"$id": "#/location",
"type": "object",
"properties": {
"location": {
"type": "string"
},
"coordinates": {
"$ref": "#/lat-lon-coords"
}
},
"required": [
"location",
"coordinates"
],
"additionalProperties": false
},
"lat-lon-coords": {
"$id": "#/lat-lon-coords",
"type": "object",
"properties": {
"lat": {
"type": "number",
"minimum": -90,
"maximum": 90
},
"lon": {
"type": "number",
"minimum": -180,
"maximum": 180
}
},
"required": [
"lat",
"lon"
]
},
} It panics when trying to compile the |
Thank you so much for reporting! I'll take a look at it soon :) |
Thanks for this useful library ;) |
Thanks for fixing the panic, @Stranger6667. Now the panic is gone but the regression itself is not fixed. It still says |
I might be misunderstand the specification but I think the above case is similar to the case described in https://json-schema.org/understanding-json-schema/structuring#defs: {
"$id": "https://example.com/schemas/customer",
"type": "object",
"properties": {
"first_name": { "$ref": "#/$defs/name" },
"last_name": { "$ref": "#/$defs/name" },
"shipping_address": { "$ref": "/schemas/address" },
"billing_address": { "$ref": "/schemas/address" }
},
"required": ["first_name", "last_name", "shipping_address", "billing_address"],
"$defs": {
"name": { "type": "string" }
}
} The |
Pasting in the above schema into the test you added works, so probably we now arrived a different but related issue after all. Will investigate, the problem is still that I have to add printlns to jsonschema to figure out which sub-schema file is the problem... |
hi @jrudolph I believe that the issue is in the After finishing with drafts support I plan to address error messages and there will be much more context for such cases, which will also pinpoint the exact error location & will have a more descriptive message. However, maybe some immediate patches to this specific area of URIs will help, I'll take a look (maybe just adding the input values to the error message will help with debugging) |
That sounds good and I'll also try to debug where the problem is now. |
I added printlns and a panic at the right position and ended up with this:
So, it does not happen inside the document but when reference from an outside schema. I'll try to figure out a test case. |
Here's a failing test case for ref_.rs:
|
Thanks, that would help me a lot! I merged a change for better URI-related errors and will take a look at the issue soon |
Great, thanks! |
Right now, the reference resolving process works as follows:
The issue appears to be a typo in This version should work, but there is an issue with eager resolving that does not check # root (note that there is no $id)
{
"$ref": "/indirection#/baz"
}
# /indirection
{
"$id": "/indirection",
"baz": {
"$ref": "/types#/foo"
}
}
# /types
{
"$id": "/types",
"foo": {
"$ref": "#/bar"
},
"bar": {
"type": "integer"
}
} But it works with Python's import jsonschema
from referencing import Registry, Resource
from referencing.jsonschema import DRAFT201909
a = {
"$id": "/indirection",
"baz": {"$ref": "/types#/foo"},
}
b = {
"$id": "/types",
"foo": {"$ref": "#/bar"},
"bar": {"type": "integer"},
}
def retrieve(uri):
contents = {"/indirection": a, "/types": b}[uri]
return Resource.from_contents(contents, default_specification=DRAFT201909)
registry = Registry(retrieve=retrieve)
schema = {
"$ref": "/indirection#/baz",
}
validator = jsonschema.Draft201909Validator(schema, registry=registry)
assert validator.is_valid(2)
assert not validator.is_valid("key") So, there is definitely a bug with eager ref resolving which should be fixed. On the schema side, do you think that my assumption about the typo is correct? At least this is my understanding of the resolution process, which was more or less ported from Python's |
Oh indeed, the trailing slash is a typo, but is that really related to the error which complains about a fragment in the base URL? |
I think it is misleading right now:
That actually could be just |
For me it still fails without the trailing slash. Basically, I'd like to have both tests passing that I added here: |
Not sure why that would be misleading? Isn't it an error coming directly out of fluent_uri::UriRef::resolve_against and happens because the base has a fragment defined? |
Sorry for the delay, I am going to make a new release with the current changes (as there are quite a lot of things already) and will follow up a bit later next week with fixes on the issues we've discussed here. Right now I don't have much time to dive into resolving to implement a proper fix.
Oh, you're right. Now I re-read it and it makes sense, as with that typo it becomes a URI with a fragment. My intention was to find a way to make the error more connected with what is defined in the schema, so there is something actionable in the message |
Yeah, no hurry, we can stay on 0.20 for the time being, just wanting to make sure that we will have a path forward in the future.
Indeed, that's already a great improvement. |
Thanks, I'll try to see if it worked. |
I finally got to checking the new version. The error message is now much better but resolution still fails... looking into it |
I created a reproducer at #633. The issue is that |
With jsonschema 0.21, I get a panic out of jsonschema which is hard to debug because of missing detail information:
The schemas in question are relatively reference heavy, I can try to pinpoint it more closely but wanted to report it already.
The text was updated successfully, but these errors were encountered: