From 9422909cfdc4cc37afd2bd5caca58b3c48888f7b Mon Sep 17 00:00:00 2001 From: Jeff Klukas Date: Thu, 25 Jun 2020 13:44:54 -0400 Subject: [PATCH] Retry once on "invalid snapshot time" when publishing views (#1095) Fixes #1001 --- script/publish_views | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/script/publish_views b/script/publish_views index 028d9770cf..6a563bee0d 100755 --- a/script/publish_views +++ b/script/publish_views @@ -8,7 +8,9 @@ import logging from multiprocessing.pool import ThreadPool import os import sys +import time +from google.api_core.exceptions import BadRequest from google.cloud import bigquery import sqlparse @@ -58,7 +60,17 @@ def process_file(client, args, filepath): if args.dry_run: print(f"Validated definition of {target_view} in {filepath}") else: - query_job.result() + try: + query_job.result() + except BadRequest as e: + if "Invalid snapshot time" in e.message: + # This occasionally happens due to dependent views being + # published concurrently; we wait briefly and give it one + # extra try in this situation. + time.sleep(1) + client.query(sql, job_config).result() + else: + raise print(f"Published view {target_view}") else: print(