-
Notifications
You must be signed in to change notification settings - Fork 286
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
ValidationError is not Hashable (2.0.0) #452
Comments
Correction. I have no clue if it was working in v1.1. Yet this would be great to be able to |
Your code works in Python 2, but breaks in Python 3 because there the language auto-sets In Python an object can only be hashable if it has a hash value which never changes during its lifetime, that is, it is immutable. We have a "problem" right now with the ErrorMessages in that they are mutable (they contain a list of messages and a Also, hashable objects which compare equal must have the same hash value, and we use the instance Python itself does not require Exceptions to be immutable. At least in 2002, GVR was in favor of mutable exceptions: https://mail.python.org/pipermail/python-dev/2002-August/027900.html The The fix to support logging is to make all schematics exceptions immutable. I don't have a proposal for how to do this, but would welcome a PR. |
issue schematics#452: all exception types are now hashable and immutable issue schematics#445: a human readable and primitive only option is available (e.g. for json serialization) issue schematics#369: follows PEP-352 conventions, and normalizes all errors found in an .errors attribute
* Enhancing and addressing some issues around exceptions: issue #452: all exception types are now hashable and immutable issue #445: a human readable and primitive only option is available (e.g. for json serialization) issue #369: follows PEP-352 conventions, and normalizes all errors found in an .errors attribute * string representations of error messages are equivalent to json formatting a primitive representation. This representation was chosen for legibility and simplicity. It's an implementation detail to serialize to json, and shouldn't be relied on. (serializing `to_primitive` exists for that purpose) * errors dicts and lists are converted to FrozenDict and FrozenList. Although they might contain mutable data inside, we expect that indicating the base container as immutable users will understand not to mutate data inside (it's not clear what problems it would cause, the goal is simply to provide an immutable interface for the Schematics errors). * exceptions instantiation now with a single parameter, that is the error object (string, list, dict or other). * exceptions `repr` can be `eval`d.
Fixed in #477 |
I can't
logging.exception(ValidationError)
it seems that the object is not hashable.That's sad, it used to work pretty well on 1.1. I'm using Python 3.4.
The text was updated successfully, but these errors were encountered: