-
Notifications
You must be signed in to change notification settings - Fork 760
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
PyErr drops the traceback on into_py(py). #3327
Comments
Thanks @zakstucke for the report. Based on your snippet above, I was able to create two following failing tests: #[test]
fn test_err_from_value() {
Python::with_gil(|py| {
let locals = PyDict::new(py);
// Produce an error from python so that it has a traceback
py.run(
r"
try:
raise ValueError('raised exception')
except Exception as e:
err = e
",
None,
Some(locals),
)
.unwrap();
let err = PyErr::from_value(locals.get_item("err").unwrap());
let traceback = err.value(py).getattr("__traceback__").unwrap();
assert!(err.traceback(py).unwrap().is(traceback));
})
}
#[test]
fn test_err_into_py() {
Python::with_gil(|py| {
let locals = PyDict::new(py);
// Produce an error from python so that it has a traceback
py.run(
r"
def f():
raise ValueError('raised exception')
",
None,
Some(locals),
)
.unwrap();
let f = locals.get_item("f").unwrap();
let err = f.call0().unwrap_err();
let traceback = err.traceback(py).unwrap();
let err_object = err.clone_ref(py).into_py(py).into_ref(py);
assert!(err_object.getattr("__traceback__").unwrap().is(traceback));
})
} I think there's actually two separate bugs here:
I suspect these might work on Python 3.12 (after #3306), because on 3.12 the exception isn't split up inside the interpreter internals. So I would argue these are bugs. I suggest we make two PRs to fix them each in turn. I can try get to this after #3306 is merged to avoid pain of rebasing. Alternatively if you are interested in submitting PRs here, the help is appreciated :) |
@davidhewitt opened PR, seemed straightforward enough! |
Fixes #20460. Caused by PyO3/pyo3#3327. Nothing in the [changelog](https://pyo3.rs/v0.20.0/changelog.html) stands out to me as a super-immediate need so doing the minimal upgrade.
Fixes #20460. Caused by PyO3/pyo3#3327. Nothing in the [changelog](https://pyo3.rs/v0.20.0/changelog.html) stands out to me as a super-immediate need so doing the minimal upgrade.
Fixes #20460. Caused by PyO3/pyo3#3327. Nothing in the [changelog](https://pyo3.rs/v0.20.0/changelog.html) stands out to me as a super-immediate need so doing the minimal upgrade.
Bug Description
As mentioned in pydantic/pydantic-core#780.
Because
into_py(py)
seems to directly convert thepvalue
, rather than the full state, the traceback is dropped.Can be fixed by manually re-attaching the tb to
__traceback__
of the output object.Steps to Reproduce
Backtrace
No response
Your operating system and version
Ubuntu 22.04
Your Python version (
python --version
)3.11.4
Your Rust version (
rustc --version
)1.71.0
Your PyO3 version
0.19.1
How did you install python? Did you use a virtualenv?
apt
Additional Info
No response
The text was updated successfully, but these errors were encountered: