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
Error in early release 3.0.0.a3 but not in 2.6.0 #509
Comments
Hm, my response didn't seem to come through here, so typing it out again (fingers crossed GitHub): I'd guess this likely has to do with the type checker interface changes. Though if so, thanks for filing this, maybe it's a nudge to change the interface slightly more. Though overall, unless you have a good reason for doing it in your real code, not sure why you're using And thanks! Glad it's helping you. |
Ah okay. I'll try extend. I was basically following the example at this link because I wanted to have a custom check on a particular number. Then the example I included here was a stripped down example. |
Bit of a shame that link became a blog post instead of just a pull request adding some prose docs for those cases, would have been happy to merge something like it. Who knows if it's correct :), will have to read through it, but yeah I suspect that you likely do want extend. |
Using extend worked perfectly. From the above sample I changed MyValidator to: MyValidator = jsonschema.validators.extend(validator=Draft4Validator,
validators=all_validators) I tried it with 3.0.0.a3 and Draft4Validator, Draft6Validator and Draft7Validators. No problems. The sample I provided didn't really what show what we were doing. We are adding a new validator to check a number against a regex pattern. def custom_number_pattern_validator(validator, value, instance, schema):
if isinstance(instance, Number):
if re.match(value, str(instance)) is None:
yield ValidationError(f'{instance} does not pass number pattern format check.')
# extend the validator to include our custom validation...
VALIDATOR = validators.extend(validator=Draft7Validator,
validators={'customNumberPattern': custom_number_pattern_validator}) To us this was a clear win because we have conditions where a number should be a certain amount of max decimal places, a certain max 'size' to the right and left of the decimal, stuff like that. We can express that 'rule' with a regex, return an error if it doesn't match and skip coding that logic everywhere it's needed. I suppose we could make the type 'string' and use 'pattern' but for some reason that just seems wrong when we really do have a number data type. :) I'm going to stay with the 3.0.0.a3 and the Draft 7 validator while we develop. |
Sorry, didn’t mean to close 😊
From: Julian Berman <notifications@github.com>
Sent: Thursday, January 10, 2019 4:59 PM
To: Julian/jsonschema <jsonschema@noreply.github.com>
Cc: Bouffard, Tim <bouffard@isc.upenn.edu>; State change <state_change@noreply.github.com>
Subject: Re: [Julian/jsonschema] Error in early release 3.0.0.a3 but not in 2.6.0 (#509)
Reopened #509<#509>.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub<#509 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AG7TTPnC2KFMjYqg1kIXQab7zWPe6vIUks5vB8WYgaJpZM4Zk9Dc>.
|
No worries! |
I'm sure I'm just doing something wrong but in version 2.6.0 this code works for both validation calls. In the newer version the second validation call fails.
This is python 3.6 if that makes any difference. I tried it for 3.0.0.a3, a2 and a1 - same error.
Product is awesome btw. Very helpful with what I need to do.
The text was updated successfully, but these errors were encountered: