def handledbexc(cols_to_print_on_err, update=False):
"""Returns a **function** to be passed to pdsql functions when inserting/ updating
the db. Basically, it prints to log"""
if not cols_to_print_on_err:
return None
def hde(dataframe, exception):
if not empty(dataframe):
try:
# if sql-alchemy exception, try to guess the orig atrribute which represents
# the wrapped exception
# http://docs.sqlalchemy.org/en/latest/core/exceptions.html
errmsg = str(exception.orig)
except AttributeError:
# just use the string representation of exception
errmsg = str(exception)
len_df = len(dataframe)
msg = MSG("%d database rows not %s" % (len_df, "updated" if update else "inserted"),
errmsg)
logwarn_dataframe(dataframe, msg, cols_to_print_on_err)
return hde
评论列表
文章目录