Save and restore the exception in WithMgpModule
Reviewers: mferencevic, ipaljak, llugovic Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2731
This commit is contained in:
parent
4b5068e455
commit
d4c2798551
@ -230,6 +230,11 @@ inline std::ostream &operator<<(std::ostream &os,
|
||||
return ExceptionInfo{Object(exc_type), Object(exc_value), Object(traceback)};
|
||||
}
|
||||
|
||||
inline void RestoreError(ExceptionInfo exc_info) {
|
||||
PyErr_Restore(exc_info.type.Steal(), exc_info.value.Steal(),
|
||||
exc_info.traceback.Steal());
|
||||
}
|
||||
|
||||
/// Append `dir` to Python's `sys.path`.
|
||||
///
|
||||
/// The function does not check whether the directory exists, or is readable.
|
||||
|
@ -1405,7 +1405,11 @@ auto WithMgpModule(mgp_module *module_def, const TFun &fun) {
|
||||
CHECK(py_query_module);
|
||||
CHECK(py_mgp.SetAttr("_MODULE", py_query_module));
|
||||
auto ret = fun();
|
||||
auto maybe_exc = py::FetchError();
|
||||
CHECK(py_mgp.SetAttr("_MODULE", Py_None));
|
||||
if (maybe_exc) {
|
||||
py::RestoreError(*maybe_exc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user