human
Complete this python program:
def _retry_on_integrity_error(func):
assistant
#Here is the Python code you requested.

    """Wraps a database function so that it gets retried on IntegrityError,
    with `delete_existing=True` passed in.
    Args:
    func: function that returns a Deferred and accepts a `delete_existing` arg
    """
    @wraps(func)
    @defer.inlineCallbacks
    def f(self, *args, **kwargs):
        try:
            res = (yield func(self, *args, **kwargs))
        except self.database_engine.module.IntegrityError:
            logger.exception('IntegrityError,    retrying.')
            res = (yield func(self, delete_existing=True, *args, **kwargs))
        defer.returnValue(res)
    return f