-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[BUG] test_methods_and_attributes.py crash in cpython 3.9 debug build #2682
Comments
This is a duplicate of #2422 |
Yup indeed. Sorry, @albanD, I guess parts of my brain were already sleeping yesterday, when you said there were other issues with the debug build and I forgot to mention #2422. To fix this issue, I think the workaround from @bstaletic in #2422 (#2422 (comment)) is better, more localized. Afterwards, we need to still check how to properly fix this and #2336. But fixing that needs to take more context into account (i.e., in #2336, we do want things to throw!), so a larger survey needs to happen to see how to best fix it. @bstaletic's workaround should still fix the debug builds, though? |
Issue description
The test test_methods_and_attributes crashes with the following stack trace:
Reproducible example code
Run the test suite with cpython 3.9 debug build (with a temporary fix for #2681 otherwise that other issue make it fail before).
Potential root cause
I think the issue is as follows:
=
step ofpy::arg("a") = UnregisteredType();
pybind11/include/pybind11/cast.h
Line 753 in af8849f
pybind11/include/pybind11/cast.h
Lines 508 to 509 in af8849f
=
call. (But with the python error set)Note that the empty value field is already properly handled by the def code and ends up raising the proper error here (and erase the previous one) when you use a non-debug build:
pybind11/include/pybind11/attr.h
Line 402 in af8849f
Proposed fix
Even though the comment for "src_and_type" explicitly states: "If the type is unknown, sets the error and returns a pair with .second = nullptr. (p.first = nullptr is not an error: it becomes None)." I am not sure how true this is. In particular, from what I can see, this result is always passed to the "type_caster_generic::cast" function which will return None when the first is nullptr without ever checking the second.
From what I have seen in the codebase, I would suggest removing the code that sets the error, just return a pair of nullptr and update the comment to mention that they are treated in a special way later.
Let me know if there are other part of the code I should look into that access these functions as well!
The text was updated successfully, but these errors were encountered: