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

Feature request: make "context in exceptions" optional #187

Closed
vanschelven opened this issue Sep 19, 2024 · 3 comments
Closed

Feature request: make "context in exceptions" optional #187

vanschelven opened this issue Sep 19, 2024 · 3 comments

Comments

@vanschelven
Copy link

I'm using fjs to generate python code that does the validation (i.e. compile_to_code)

I'm working around #72 by just falling back to good (bad) old jsonschema and best_guess in the case I have a validationerror.

That means I don't use any of the information that's present in the JsonSchemaValueException. Looking at that code, I noticed that ~75% (out of a whopping 2.5MB) is used by the definition parts of the generated exceptions. When you have deeply nested definitions, that is to be expected, since the relevant part of the definition (for some part) is repeated throughout the tree.

Since I don't use that information, generating it (and loading it) seems wasteful. It would be nice if compile_to_code had a parameter that controlled the behavior of the generated raise JsonSchemaValueException, basically making (the relevant parts of) this commit conditional.

I managed to work around this a bit by hacking around in def exc but that doesn't "quite feel right".

@vanschelven vanschelven changed the title Feature request: definition arg (and possibly more) of JsonSchemaValueException optionally generated Feature request: make "context in exceptions" optional Sep 19, 2024
@horejsek
Copy link
Owner

horejsek commented Nov 3, 2024

That is an exciting idea. I will measure how it changes the performance, and if it's improving it significantly, I will provide an option for that.

@horejsek
Copy link
Owner

horejsek commented Nov 3, 2024

A quick check shows it could reduce time by 50%! For cases when you expect mostly valid inputs and you don't care about details, it could speed up greatly the performance. Will provide this feature for sure. :-)

@horejsek
Copy link
Owner

Added detailed_exceptions parameter that is True by default and can be turned off in v2.21.0. It can be twice as fast.

vanschelven added a commit to bugsink/bugsink that referenced this issue Nov 28, 2024
We don't use fastjsonschema's exception info, falling back to jsonschema for that. Not using the info is faster.
Possible because horejsek/python-fastjsonschema#187 was completed.

I did not at present do any speed/memory checks, but the diff is quite promising :-)
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

No branches or pull requests

2 participants