-
Notifications
You must be signed in to change notification settings - Fork 292
Preserve exception instances and their context in ValidationError #753
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
Conversation
please review cc @lig |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #753 +/- ##
==========================================
+ Coverage 93.64% 93.65% +0.01%
==========================================
Files 99 99
Lines 13929 13970 +41
Branches 25 25
==========================================
+ Hits 13044 13084 +40
- Misses 879 880 +1
Partials 6 6
Continue to review full report in Codecov by Sentry.
|
CodSpeed Performance ReportMerging #753 will degrade performances by 60.91%Comparing Summary
Benchmarks breakdown
|
maybe @samuelcolvin if you want to review since David is out today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I like the repr tests. So, replacing string in error
with an exception instance should break anything in Pydantic.
Still, we should test this with Pydantic tests before merging, I think.
Agreed, we'll have to update some tests, looks like it's about 20 it shouldn't be too bad. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the Option<PyObject>
feels like a shortcut for the sake of default that has created a little bit of pain in the rest of the implementation.
I'd like to suggest having the following type:
struct InnerError(PyErr);
// to use for the error "context" default in EnumIter
impl Default for InnerError {
fn default() -> Self {
Self(PyException::new_err(()))
}
}
impl ToPyObject for InnerError {
fn to_object(&self, py: Python<'_>) -> PyObject {
self.0.to_object(py)
}
}
If you use that instead of error: Option<PyObject>
, I think the rest of the code will come out cleaner.
Is that really better? The default seems to be just as meaningless as |
Ah, I'd missed the need for a impl Clone for InnerError {
fn clone(&self) -> Self {
Python::with_gil(|py| Self(self.0.clone_ref(py)))
}
} However I take your point that this is now also quite verbose.
At the moment I believe the |
Well, in theory, I think the default option for these members of the enum will never be exposed to users. If we had a bug and they did, I don’t think one of the other would be more meaningful to a user experiencing the bug. Neither would crash or anything like that. Obviously, the better option would be to prove to the compiler that this is the case but I imagine that would require extensive refactoring. |
Co-authored-by: David Hewitt <[email protected]>
please review |
Looks like I need to sync up with main, I’ll do that later today but let me know if everything else looks good @davidhewitt so I can handle that async |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Fixes pydantic/pydantic#6504
Selected Reviewer: @davidhewitt