You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cannot log ValidationError as an exception. Making the exceptions hashable would be great to use in standard logging libraries. Any plans to make ValidationError exception hashable before the v3.0 release??
Hey yeah this is one of the remaining things I'm thinking about before the release.
The issue with making them hashable is that doing so requires an API change, because they've got mutable attributes on them at the minute, so those would need to become immutable ones.
Of course, ValidationError and SchemaError would be trivially hashable if they didn't define __eq__. Is it necessary for those classes to be comparable? I tried grepping the jsonschema code base for == and !=, and as far as I can tell, exceptions are never explicitly compared. (But I could definitely be missing implicit comparisons, such as if exc in mylist:, etc.)
If comparability is not necessary, I vote for simply removing _Error.__eq__() and _Error.__ne__().
Making the exceptions hashable would be great to use in standard logging libraries.
Here's another use-case: pytest can't handle unhashable exceptions, so any users whose tests might raise a ValidationError will currently see an INTERNALERROR traceback from pytest, crashing the whole test suite.
Here's another use-case: pytest can't handle unhashable exceptions, so any users whose tests might raise a ValidationError will currently see an INTERNALERROR traceback from pytest, crashing the whole test suite.
Sounds like a py.test bug worth filing regardless, though presumably it's just the same underlying one (that py~34-36 broke this, and then fixed it again in 3.7). pytest seems like the sort of thing though that should be trying to fix it even on those though.
Activity
Julian commentedon Oct 17, 2018
Hey yeah this is one of the remaining things I'm thinking about before the release.
The issue with making them hashable is that doing so requires an API change, because they've got mutable attributes on them at the minute, so those would need to become immutable ones.
[-]can't logging.exception(ValidationError), raises Exception TypeError: unhashable type: 'ValidationError'[/-][+]Make ValidationError Hashable[/+]stuarteberg commentedon Nov 30, 2018
Of course,
ValidationErrorandSchemaErrorwould be trivially hashable if they didn't define__eq__. Is it necessary for those classes to be comparable? I tried grepping thejsonschemacode base for==and!=, and as far as I can tell, exceptions are never explicitly compared. (But I could definitely be missing implicit comparisons, such asif exc in mylist:, etc.)If comparability is not necessary, I vote for simply removing
_Error.__eq__()and_Error.__ne__().For now, here's my workaround:
Here's another use-case:
pytestcan't handle unhashable exceptions, so any users whose tests might raise aValidationErrorwill currently see anINTERNALERRORtraceback frompytest, crashing the whole test suite.For example:
Julian commentedon Dec 4, 2018
It's used in tests, yes, via
assertEqual.Sounds like a
py.testbug worth filing regardless, though presumably it's just the same underlying one (that py~34-36 broke this, and then fixed it again in 3.7). pytest seems like the sort of thing though that should be trying to fix it even on those though.Make exceptions hashable (but not comparable)
Make exceptions hashable (but not comparable)
Make exceptions hashable (but not comparable)
stuarteberg commentedon Dec 6, 2018
Ah, thanks for pointing that out. Still, it's not used in many places, so I've proposed #502 to eliminate the need for comparable exceptions.
OK, I've submitted pytest-dev/pytest#4514, to see if they're interested in supporting unhashable exceptions.
Make exceptions hashable (but not comparable)
stuarteberg commentedon Dec 6, 2018
FWIW, you're right: This is not an issue when using Python 3.7. I'm using Python 3.6, where it is an issue.
Squashed 'json/' changes from 15ec577f..09fd353f