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:
Teon Banek 2020-03-19 12:47:21 +01:00
parent 4b5068e455
commit d4c2798551
2 changed files with 9 additions and 0 deletions

View File

@ -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.

View File

@ -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;
}