Skip to content

Commit 3b620b2

Browse files
[io] fix: supress conflict error when creating dataset in parallel
1 parent ae6e8f7 commit 3b620b2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

libs/io/garf_io/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# limitations under the License.
1414
"""Write GarfReport to anywhere."""
1515

16-
__version__ = '0.1.1'
16+
__version__ = '0.1.2'

libs/io/garf_io/writers/bigquery_writer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'Please install garf-io with BigQuery support - `pip install garf-io[bq]`'
2828
) from e
2929

30+
import contextlib
3031
import logging
3132

3233
import numpy as np
@@ -117,9 +118,12 @@ def create_or_get_dataset(self) -> bigquery.Dataset:
117118
try:
118119
bq_dataset = self.client.get_dataset(self.dataset_id)
119120
except google_cloud_exceptions.NotFound:
120-
bq_dataset = bigquery.Dataset(self.dataset_id)
121+
dataset_id = f'{self.project}.{self.dataset_id}'
122+
bq_dataset = bigquery.Dataset(dataset_id)
121123
bq_dataset.location = self.location
122-
bq_dataset = self.client.create_dataset(bq_dataset, timeout=30)
124+
with contextlib.suppress(google_cloud_exceptions.Conflict):
125+
bq_dataset = self.client.create_dataset(bq_dataset, timeout=30)
126+
logger.info('Created new dataset %s', dataset_id)
123127
return bq_dataset
124128

125129
@tracer.start_as_current_span('bq.write')

0 commit comments

Comments
 (0)