def METHOD_NAME(self, user_id, template_id):
    with app.app_context():
        if r.table("users").get(user_id).run(db.conn) is None:
            raise Error("not_found", "User not found", traceback.format_exc())
    # Has a desktop with this template? Then return it (start it if stopped)
    with app.app_context():
        desktops = list(
            r.db("isard")
            .table("domains")
            .get_all(user_id, index="user")
            .filter({"from_template": template_id, "persistent": False})
            .run(db.conn)
        )
    if len(desktops) == 1:
        if desktops[0]["status"] == "Started":
            return desktops[0]["id"]
        desktop_start(desktops[0]["id"], wait_seconds=1)
        return desktops[0]["id"]
    # If not, delete all nonpersistent desktops based on this template from user
    desktops_non_persistent_delete(user_id, template_id)
    # and get a new nonpersistent desktops from this template
    return self._nonpersistent_desktop_create_and_start(user_id, template_id)