def METHOD_NAME(instance, *args, **kwargs):  # noqa: max-complexity=11
    if not instance.image:
        return
    path = None
    try:
        path = os.path.dirname(instance.image.path)
    except NotImplementedError:
        # This backend storage doesn't implement 'path' so there is no path to delete
        pass
    except ValueError:
        # in case of Value error
        # https://github.com/django-wiki/django-wiki/issues/936
        pass
    finally:
        # Remove image file
        instance.image.delete(save=False)
    if path is None:
        # This backend storage doesn't implement 'path' so there is no path to delete
        # or some other error (ValueError)
        return
    # Clean up empty directories
    # Check for empty folders in the path. Delete the first two.
    if len(path[-1]) == 32:
        # Path was (most likely) obscurified so we should look 2 levels down
        max_depth = 2
    else:
        max_depth = 1
    for depth in range(0, max_depth):
        delete_path = "/".join(path[:-depth] if depth > 0 else path)
        try:
            dir_list = os.listdir(os.path.join(django_settings.MEDIA_ROOT, delete_path))
        except OSError:
            # Path does not exist, so let's not try to remove it...
            dir_list = None
        if not (dir_list is None) and len(dir_list) == 0:
            os.rmdir(delete_path)