Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/errors/validation_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,20 @@ impl ValidationError {
fn __str__(&self, py: Python) -> String {
self.__repr__(py)
}

fn __reduce__(slf: &PyCell<Self>) -> PyResult<(&PyAny, PyObject)> {
let py = slf.py();
let callable = slf.getattr("from_exception_data")?;
let borrow = slf.try_borrow()?;
let args = (
borrow.title.as_ref(slf.py()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be

Suggested change
borrow.title.as_ref(slf.py()),
borrow.title.as_ref(py),

like the rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 👍

borrow.errors(py, include_url_env(py), true, true)?,
borrow.input_type.into_py(py),
borrow.hide_input,
)
.into_py(slf.py());
Ok((callable, args))
}
}

// TODO: is_utf8_char_boundary, floor_char_boundary and ceil_char_boundary
Expand Down
9 changes: 9 additions & 0 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import pickle
import re
import sys
from decimal import Decimal
Expand Down Expand Up @@ -1074,3 +1075,11 @@ def test_hide_input_in_json() -> None:

for error in exc_info.value.errors(include_input=False):
assert 'input' not in error


def test_validation_error_pickle() -> None:
s = SchemaValidator({'type': 'int'})
with pytest.raises(ValidationError) as exc_info:
s.validate_python('definitely not an int')

pickle.loads(pickle.dumps(exc_info.value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test that the unpickled value is equivalent to the original?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check .errors are equivalent, as I want to steer clear from implementing equality for the whole objects (as that's a much bigger change).