def METHOD_NAME(self, task):
    """
        Function to set maintenance task to error, to allow retry of the operation linked to maintenance.
    """
    try:
        app = get_app('maintenance')
        for model in get_models(app):
            if hasattr(model, 'task'):
                obj_maintenance = model.objects.filter(task=task).first()
                if obj_maintenance:
                    self.task.add_detail(
                        "Setting {}-{} status to ERROR".format(
                            model.__name__, obj_maintenance.id
                        ), level=0
                    )
                    obj_maintenance.set_error()
    except Exception as error:
        self.task.add_detail(
            "ERROR: {} to update maintenance to error.".format(
                error
            ), level=0
        )
        raise Exception(error)