Answer to "retrieve the error stack trace to save to the database" from comment:
https://docs.python.org/3/library/traceback.html
Use the methods of traceback
to convert the trace of the exception into a string which you can then store in the database.
Also on the above page:
New in version 3.5.
StackSummary objects represent a call stack ready for formatting.
The short short example with an exception object:
>>> an_error = IndexError('tuple index out of range')
>>> traceback.print_exception(type(an_error), an_error, an_error.__traceback__)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
IndexError: list index out of range
See also Extract traceback info from an exception object:
You don't need to re-raise the exception, though, the traceback is in the __traceback__
attribute.