{"record":{"id":"832691721aad71e0","repo":"apache/beam","slug":"invalid-bigquery-table-name-s-see-https-cloud-google-com","errorCode":null,"errorMessage":"Invalid BigQuery table name: %s \nSee https://cloud.google.com/bigquery/docs/tables#table_naming","messagePattern":"Invalid BigQuery table name: (.+?) \nSee https://cloud\\.google\\.com/bigquery/docs/tables#table_naming","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery_tools.py","lineNumber":829,"sourceCode":"    Raises:\n      HttpError: if lookup failed.\n    \"\"\"\n    request = bigquery.BigqueryTablesGetRequest(\n        projectId=project_id, datasetId=dataset_id, tableId=table_id)\n    response = self.client.tables.Get(request)\n    return response\n\n  def _create_table(\n      self,\n      project_id,\n      dataset_id,\n      table_id,\n      schema,\n      additional_parameters=None):\n\n    valid_tablename = regex.fullmatch(_TABLE_PATTERN, table_id, regex.ASCII)\n    if not valid_tablename:\n      raise ValueError(\n          'Invalid BigQuery table name: %s \\n'\n          'See https://cloud.google.com/bigquery/docs/tables#table_naming' %\n          table_id)\n\n    additional_parameters = additional_parameters or {}\n    table = bigquery.Table(\n        tableReference=TableReference(\n            projectId=project_id, datasetId=dataset_id, tableId=table_id),\n        schema=schema,\n        **additional_parameters)\n    request = bigquery.BigqueryTablesInsertRequest(\n        projectId=project_id, datasetId=dataset_id, table=table)\n    response = self.client.tables.Insert(request)\n    _LOGGER.debug(\"Created the table with id %s\", table_id)\n    # The response is a bigquery.Table instance.\n    return response\n\n  @retry.with_exponential_backoff(","sourceCodeStart":811,"sourceCodeEnd":847,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery_tools.py#L811-L847","documentation":"Raised by `_create_table` in `apache_beam/io/gcp/bigquery_tools.py` when the given table_id does not fullmatch `_TABLE_PATTERN` (checked with regex.ASCII). BigQuery table names must match `[a-zA-Z0-9_]+` (with optional dataset/project qualifiers), so illegal characters like dashes, dots, or unicode cause this ValueError before any API call is made. It is a client-side preflight guard so invalid names fail fast.","triggerScenarios":"Calling `get_or_create_table` (or `WriteToBigQuery` with a computed table name) where table_id contains characters outside [a-zA-Z0-9_], e.g. 'my-table', 'table-2024-01', or a name built from user input with spaces/hyphens.","commonSituations":"Dynamically constructing table names from dates, filenames, or user/tenant IDs that contain hyphens or other punctuation; copying PostgreSQL/MySQL table names that allow hyphens; accidentally passing a full 'project:dataset.table' string where only the bare table id is expected with different validation.","solutions":["Sanitize the table_id: replace invalid characters with '_' (e.g. re.sub(r'[^a-zA-Z0-9_]', '_', table_id)) before calling the API.","Verify you are passing only the table identifier (or a correctly formed 'project:dataset.table') and that dataset/project qualifiers use allowed characters.","If a hyphenated source name must be preserved, map it to a deterministic underscore-based name and keep the original as a label/metadata.","Test the name with re.fullmatch on the BigQuery pattern locally before launching the pipeline."],"exampleFix":"// before\nname = f'{tenant}-{date}'\nbeam.io.WriteToBigQuery(f'dataset.{name}', ...)\n// after\nimport re\nname = re.sub(r'[^a-zA-Z0-9_]', '_', f'{tenant}_{date}')\nbeam.io.WriteToBigQuery(f'dataset.{name}', ...)","handlingStrategy":"validation","validationCode":"import re\n_TABLE_PATTERN = r'((?:[a-zA-Z0-9-]+[.:])?)([a-zA-Z0-9_]+)\\.([a-zA-Z0-9_]+)'\ndef valid_table_id(table_id):\n    return re.fullmatch(_TABLE_PATTERN, table_id, re.ASCII) is not None\n# call before get_or_create_table / WriteToBigQuery","typeGuard":"def is_valid_table_name(table_id):\n    return isinstance(table_id, str) and bool(re.fullmatch(r'([\\w-]+[.:])?\\w+\\.\\w+', table_id, re.ASCII))","tryCatchPattern":null,"preventionTips":["Sanitize dynamic table names with re.sub(r'[^a-zA-Z0-9_]', '_', name).","Add a unit test that every computed destination name passes the BigQuery pattern.","Keep tenant/file-derived names mapped through a slugify function before use."],"tags":["bigquery","python","validation","naming"],"backgroundTag":"invalid-identifier-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}