def check_view_exists()

in python/lookerstudio/lookerstudio_deployment.py [0:0]


def check_view_exists(resource_id:str) -> bool:
    """ Opens connection to BigQuery, \cCheck if view exists and account has access.
    
    Accepts a string Resource ID as a parameter. Expects Resource ID to be formatted. `ProjectId.DatasetId.TableId`
    
    Returns True if view exists and is accessible. """

    view_exists = True

    try:
        bq_client.get_table(resource_id)
    # Catch exception if path to view does not exist and sets view_exists to false for further processing.
    except NotFound:
        print(f"ERROR: `{resource_id}` not found. Ensure the path is correct and the view has been created.")
        view_exists = False
    # Catch exception if path to view exists but user does not have access and sets view_exists to false for further processing.
    except Forbidden:
        print(f"ERROR: Access denied on `{resource_id}`. Ensure your account has access.")
        view_exists = False
    except BadRequest:
        print(f"ERROR: Project in `{resource_id}` does not exist.")
        view_exists = False

    return view_exists