Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Make a couple of errors non-retryable in bigquery #21108

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion posthog/temporal/batch_exports/bigquery_batch_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ async def load_jsonl_file_to_bigquery_table(jsonl_file, table, table_schema, big
await asyncio.to_thread(load_job.result)


class InvalidFullyQualifiedIdError(Exception):
"""Exception raised on an invalid fully qualified table id."""

def __init__(self, fully_qualified_table_id: str):
msg = (
"The project id, dataset id, and table id provided did not generate a valid "
f"(e.g. 'project.dataset.table') fully qualified ID, but instead: '{fully_qualified_table_id}'"
)
super().__init__(msg)


async def create_table_in_bigquery(
project_id: str,
dataset_id: str,
Expand All @@ -61,7 +72,11 @@ async def create_table_in_bigquery(
) -> bigquery.Table:
"""Create a table in BigQuery."""
fully_qualified_name = f"{project_id}.{dataset_id}.{table_id}"
table = bigquery.Table(fully_qualified_name, schema=table_schema)

try:
table = bigquery.Table(fully_qualified_name, schema=table_schema)
except ValueError:
raise InvalidFullyQualifiedIdError(fully_qualified_name)

if "timestamp" in [field.name for field in table_schema]:
# TODO: Maybe choosing which column to use as parititoning should be a configuration parameter.
Expand Down Expand Up @@ -429,6 +444,10 @@ async def run(self, inputs: BigQueryBatchExportInputs):
"RefreshError",
# Usually means the dataset or project doesn't exist.
"NotFound",
# Raised when BigQuery detects a schema change.
"BadRequest",
# Raised when BigQuery rejects the table ID.
"InvalidFullyQualifiedIdError",
],
update_inputs=update_inputs,
)
Loading