{"record":{"id":"15b21ee4e2b436cb","repo":"apache/beam","slug":"namespace-cannot-be-empty","errorCode":null,"errorMessage":"Namespace cannot be empty.","messagePattern":"Namespace cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/testing/load_tests/load_test_metrics_utils.py","lineNumber":488,"sourceCode":"  \"\"\"A :class:`BigQueryClient` publishes collected metrics to\n  BigQuery output.\"\"\"\n  def __init__(self, project_name, table, dataset, bq_schema=None):\n    self.schema = bq_schema\n    self._namespace = table\n    self._client = bigquery.Client(project=project_name)\n    self._schema_names = self._get_schema_names()\n    schema = self._prepare_schema()\n    self._get_or_create_table(schema, dataset)\n\n  def _get_schema_names(self):\n    return [schema['name'] for schema in self.schema]\n\n  def _prepare_schema(self):\n    return [SchemaField(**row) for row in self.schema]\n\n  def _get_or_create_table(self, bq_schemas, dataset):\n    if self._namespace == '':\n      raise ValueError('Namespace cannot be empty.')\n\n    dataset = self._get_dataset(dataset)\n    table_ref = dataset.table(self._namespace)\n\n    try:\n      self._bq_table = self._client.get_table(table_ref)\n    except NotFound:\n      table = bigquery.Table(table_ref, schema=bq_schemas)\n      self._bq_table = self._client.create_table(table)\n\n  def _update_schema(self):\n    table_schema = self._bq_table.schema\n    if self.schema and len(table_schema) != self.schema:\n      self._bq_table.schema = self._prepare_schema()\n      self._bq_table = self._client.update_table(self._bq_table, [\"schema\"])\n\n  def _get_dataset(self, dataset_name):\n    bq_dataset_ref = self._client.dataset(dataset_name)","sourceCodeStart":470,"sourceCodeEnd":506,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/testing/load_tests/load_test_metrics_utils.py#L470-L506","documentation":"BigQueryClient validates that a namespace was provided before creating/looking up the BigQuery table, since the namespace doubles as the table name. An empty namespace string makes table addressing impossible, so _get_or_create_table raises immediately during client construction.","triggerScenarios":"Instantiating BigQueryClient (via __init__ -> _get_or_create_table) with namespace='' or a namespace that resolves to an empty string, e.g. from an unset pipeline option.","commonSituations":"Forgot to pass --namespace (or the metrics namespace option) when launching a load-test pipeline; option read with default '' instead of required value.","solutions":["Pass a non-empty namespace to the metrics publisher configuration","Check the pipeline option/flag that feeds the namespace and make it required or set a sensible default","Validate namespace at pipeline startup before constructing BigQueryClient"],"exampleFix":"// before\nBigQueryClient(bq_schemas, dataset, namespace='')\n// after\nBigQueryClient(bq_schemas, dataset, namespace='load-test-2024-09')","handlingStrategy":"validation","validationCode":"if not namespace or not isinstance(namespace, str):\n    raise ValueError('namespace must be a non-empty string')","typeGuard":"def valid_namespace(ns):\n    return isinstance(ns, str) and len(ns) > 0","tryCatchPattern":"try:\n    client = BigQueryClient(schemas, dataset, namespace)\nexcept ValueError:\n    _LOGGER.error('Namespace missing; pass --namespace')\n    raise","preventionTips":["Make the namespace pipeline option required","Validate all metrics options at pipeline startup","Use a naming convention like test-name + date"],"tags":["bigquery","python","configuration","empty-string"],"backgroundTag":"empty-required-field","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"}