PYTHON-5032 - Use PyErr_GetRaisedException instead of deprecated PyEr…#2795
PYTHON-5032 - Use PyErr_GetRaisedException instead of deprecated PyEr…#2795NoahStapp merged 5 commits intomongodb:masterfrom
Conversation
…r_Fetch on Python 3.12+
There was a problem hiding this comment.
Pull request overview
This PR updates the BSON C-extension’s exception-handling paths to avoid deprecated PyErr_Fetch usage on Python 3.12+ by using the newer raised-exception APIs, while preserving traceback information when re-wrapping exceptions.
Changes:
- Added a Python 3.12+ traceback-transfer helper and a shared helper to rewrap exceptions as
InvalidBSON(...). - Updated
datetime_from_milliserror augmentation to usePyErr_GetRaisedException/PyErr_SetRaisedExceptionon Python 3.12+. - Updated
handle_invalid_doc_errorto use the Python 3.12+ raised-exception APIs while reconstructingInvalidDocumentwith the document attached.
|
Test failure is a known flaky test that should be resolved by PYTHON-5821. |
| static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw); | ||
|
|
||
| /* 3.12 */ | ||
| #if PY_VERSION_HEX >= 0x030C0000 |
There was a problem hiding this comment.
silly question, is there a reason we cant make 0x030C0000 a var like PYTHON_3_12_HEX or something? (i just arbitrarily made a var name so if you can think of a better one please use it)
There was a problem hiding this comment.
Good catch, that's a big readability improvement. Done.
sleepyStick
left a comment
There was a problem hiding this comment.
otherwise, lgtm (the comments in this file are super helpful!)
…r_Fetch on Python 3.12+
PYTHON-5032
Changes in this PR
See title.
Test Plan
Existing BSON test suite.
Checklist
Checklist for Author
[ ] Did you update the changelog (if necessary)?[ ] Is any followup work tracked in a JIRA ticket? If so, add link(s).Checklist for Reviewer