-
-
Notifications
You must be signed in to change notification settings - Fork 584
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
check_schema does not resolve $refs (and so does not actually check the schema) #854
Comments
There are even things in the specification which the metaschema doesn't cover but which mean the schema isn't valid according to the specification (and But in your scenario -- what would you want |
For your specific case, though I haven't read super carefully, you may just want to try/except and if you get things other than a |
The issue is that it's NOT raising an error when it should. It raises an error in other cases, such as malformed |
As I say, a try/except when you run validation will cover that.
It doesn't validate the ref -- it's dereferencing it so that it can apply the validation rules at the thing that was referenced -- i.e. it needs to know what thing the ref refers to so it can use it. And as for why it doesn't really help to do that ahead of time:
|
A try/except is supposed to catch errors when they happen. My issue is that there are no errors to catch, but there should be.
So why doesn't it do this in
This is exactly the same issue as if it were checked only once - what happens if there are transient network errors when |
An exception occurs at validation time (as opposed to when you ran check_schema) -- you pasted it in this ticket. Catch that in a try/except.
This is precisely my point. |
I think I know your confusion now. In the stacktrace, it says this line generates the error:
However, it should be an error from 3 lines above it that reads:
If you notice in the output, it says:
The first two lines are the |
I don't believe I'm confused -- I know what you're asking, I've explained why it's not well defined, and suggested what you can do instead. |
The only other thing I can add is perhaps what you want is python-jsonschema/referencing#2 and to pre-resolve your schema -- a PR is welcome for that! |
Here is my feature suggestion, then:
(I still don't understand why it currently does not, but that is beside the point.) |
I've explained why I believe that isn't a guarantee check_schema can make (i.e. why today
And to consider (or propose) how the guarantee you're proposing (or expecting) would be consistently made were it part of check_schema's goal. You're welcome to ask follow-ups, but at the minute it seems we're talking over each other. I'm going to close this however, since I'm fairly confident it's not something that can be addressed other than via python-jsonschema/referencing#2. |
So my question is why is it a guarantee that |
Validate indeed also does not guarantee it won't raise any exception other than |
@skamansam I implemented just what you are asking for: https://github.com/robherring/dt-schema/blob/master/dtschema/lib.py#L685 Don't use a subclass though. @Julian says that's not an ABI (and 4.0.0 broke it). |
@robherring Thank you! |
I am trying to develop a system where special users can create their own fragments of a json schema, and then the system will build the schema in order to validate
config
objects. The problem I am seeing is that thecheck_schema
does not throw any errors when$ref
s are invalid, but thevalidate()
method does throw them. IMHO, this means thecheck_schema
does not fully check the schema.Schema:
Code:
In order to get validation to work, I need a
config
object. However, I want to know whether the schema is valid BEFORE I have aconfig
object, as users will be uploading their own fragment validations, so I need to know if the whole document will validate BEFORE anyone uses the schema to validate anything. (The code below is pretty much a copy ofvalidate()
.)Output
EDIT: updated the code so my problem is more clear.
The text was updated successfully, but these errors were encountered: