{"record":{"id":"8cd87c838de21009","repo":"apache/beam","slug":"temp-dataset-has-to-be-either-str-or-datasetreference","errorCode":null,"errorMessage":"temp_dataset has to be either str or DatasetReference","messagePattern":"temp_dataset has to be either str or DatasetReference","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery_read_internal.py","lineNumber":238,"sourceCode":"  def display_data(self):\n    return {\n        'use_json_exports': str(self.use_json_exports),\n        'gcs_location': str(self.gcs_location),\n        'bigquery_job_labels': json.dumps(self.bigquery_job_labels),\n        'kms_key': str(self.kms_key),\n        'project': str(self.project),\n        'temp_dataset': str(self.temp_dataset)\n    }\n\n  def _get_temp_dataset_id(self):\n    if self.temp_dataset is None:\n      return None\n    elif isinstance(self.temp_dataset, DatasetReference):\n      return self.temp_dataset.datasetId\n    elif isinstance(self.temp_dataset, str):\n      return self.temp_dataset\n    else:\n      raise ValueError(\"temp_dataset has to be either str or DatasetReference\")\n\n  def _get_temp_dataset_project(self):\n    \"\"\"Returns the project ID for temporary dataset operations.\n    \n    If temp_dataset is a DatasetReference, returns its projectId.\n    Otherwise, returns the pipeline project for billing.\n    \"\"\"\n    if isinstance(self.temp_dataset, DatasetReference):\n      return self.temp_dataset.projectId\n    else:\n      return self._get_project()\n\n  def start_bundle(self):\n    self.bq = bigquery_tools.BigQueryWrapper(\n        temp_dataset_id=self._get_temp_dataset_id(),\n        client=bigquery_tools.BigQueryWrapper._bigquery_client(self.options))\n\n  def process(self,","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery_read_internal.py#L220-L256","documentation":"ReadFromBigQuery's temp_dataset parameter names the BigQuery dataset used for temporary tables; it may be a dataset id string or a DatasetReference. _get_temp_dataset_id narrows the value: None, DatasetReference, or str are accepted; any other type raises this ValueError.","triggerScenarios":"Passing temp_dataset as a dict, a TableName, or other non-str/non-DatasetReference object to ReadFromBigQuery (or its internal _CustomBigQuerySource/_CustomBQSession transformer).","commonSituations":"Constructing a dict like {'projectId':..., 'datasetId':...} instead of a DatasetReference; passing a table reference rather than a dataset reference.","solutions":["Pass a plain string: temp_dataset='my_temp_dataset'.","Pass apache_beam.io.gcp.internal.clients.bigquery.DatasetReference(projectId='p', datasetId='d').","Convert dict values to DatasetReference before constructing the transform."],"exampleFix":"// before\nbeam.io.ReadFromBigQuery(..., temp_dataset={'projectId': 'p', 'datasetId': 'd'})\n// after\nfrom apache_beam.io.gcp.internal.clients.bigquery import DatasetReference\nbeam.io.ReadFromBigQuery(..., temp_dataset=DatasetReference(projectId='p', datasetId='d'))","handlingStrategy":"type-guard","validationCode":"if temp_dataset is not None and not isinstance(temp_dataset, (str, DatasetReference)):\n    raise TypeError('temp_dataset must be str or DatasetReference')","typeGuard":"def is_valid_temp_dataset(v) -> bool:\n    from apache_beam.io.gcp.internal.clients.bigquery import DatasetReference\n    return v is None or isinstance(v, (str, DatasetReference))","tryCatchPattern":null,"preventionTips":["Use DatasetReference from the Beam bigquery clients library, not dicts","Do not pass TableReference where a DatasetReference is expected","Document temp_dataset's accepted types in shared pipeline helpers"],"tags":["bigquery","type-mismatch","beam","python"],"backgroundTag":"type-mismatch","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"}