def _existing_only(func):
    """Decorator for checking if roles exist"""

    @wraps(func)
    def _check_existence(
        db, entity, role=None, *, managed=False, commit=True, rolename=None
    ):
        if isinstance(role, str):
            rolename = role
        if rolename is not None:
            # if given as a str, lookup role by name
            role = orm.Role.find(db, rolename)
        if role is None:
            raise ValueError(f"Role {rolename} does not exist")

        return func(db, entity, role, commit=commit, managed=managed)

    return _check_existence
Decorator for checking if roles exist
jupyterhub/roles.py