def __exit__(self, ty, val, tb):
end = time.time()
# Ignore the problem if we just added a duplicate
if ty is None:
log('SQL execution in [{}] completed without error. Duration: [{:.3f}]'.format(
self.proc, end - self.start), proc=self.proc, v=logging.D)
# Handle duplicate entry violations
elif (ty is psycopg2.IntegrityError) and self.ignore_duplicates:
if (val.pgcode in (errorcodes.UNIQUE_VIOLATION,
errorcodes.NOT_NULL_VIOLATION,
)):
log('SQL execution in [{}] completed. Null or Unique constraint hit [{}]. Duration: [{:.3f}]'.format(
self.proc, val.pgerror, end - self.start), proc=self.proc, v=logging.I)
return True
else:
log('Finished SQL execution in [{}] after [{:.3f}] seconds with [{}] error [{}]. Traceback: [{}]'.format(
self.proc, end - self.start, ty.__name__, str(val), traceback.format_tb(tb)),
proc=self.proc, v=logging.I)
评论列表
文章目录