{"record":{"id":"423e78be70aa18d7","repo":"apache/beam","slug":"both-a-bigquery-table-and-a-query-were-specified-please","errorCode":null,"errorMessage":"Both a BigQuery table and a query were specified. Please specify only one of these.","messagePattern":"Both a BigQuery table and a query were specified\\. Please specify only one of these\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":721,"sourceCode":"      table=None,\n      dataset=None,\n      project=None,\n      query=None,\n      validate=False,\n      pipeline_options=None,\n      coder=None,\n      use_standard_sql=False,\n      flatten_results=True,\n      kms_key=None,\n      bigquery_job_labels=None,\n      use_json_exports=False,\n      job_name=None,\n      step_name=None,\n      unique_id=None,\n      temp_dataset=None,\n      query_priority=BigQueryQueryPriority.BATCH):\n    if table is not None and query is not None:\n      raise ValueError(\n          'Both a BigQuery table and a query were specified.'\n          ' Please specify only one of these.')\n    elif table is None and query is None:\n      raise ValueError('A BigQuery table or a query must be specified')\n    elif table is not None:\n      self.table_reference = bigquery_tools.parse_table_reference(\n          table, dataset, project)\n      self.query = None\n      self.use_legacy_sql = True\n    else:\n      if isinstance(query, str):\n        query = StaticValueProvider(str, query)\n      self.query = query\n      # TODO(BEAM-1082): Change the internal flag to be standard_sql\n      self.use_legacy_sql = not use_standard_sql\n      self.table_reference = None\n\n    self.method = method","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L703-L739","documentation":"Raised by the validation guard at the top of ReadFromDatastore/__init__ in apache_beam/io/gcp/bigquery.py: this transform accepts either an immutable table reference (table/dataset/project) or a SQL query (query), never both. The check `if table is not None and query is not None` fires only when the caller passed a non-None table argument together with a non-None query argument, making the read target ambiguous. Fix by supplying exactly one source: either the table path (table='project:dataset.table') or the query string, leaving the other as None.","triggerScenarios":"Constructing BigQuerySource(table=..., query=...) or calling beam.io.ReadFromBigQuery with both table and query set to non-None values.","commonSituations":"Config-driven pipelines where both keys default to values, or refactoring where an old table argument was left in place after adding a query.","solutions":["Remove the table argument and keep query, or vice versa","Make one of them conditionally None based on configuration","Check config merging so only one source key is populated"],"exampleFix":"// before\nReadFromBigQuery(table='proj:ds.tbl', query='SELECT 1')\n// after\nReadFromBigQuery(query='SELECT 1')","handlingStrategy":"validation","validationCode":"if table is not None and query is not None:\n    raise ValueError('Specify only one of table or query before constructing BigQuerySource')","typeGuard":"def source_args_ok(table, query):\n    return (table is None) != (query is None)","tryCatchPattern":"try:\n    source = BigQuerySource(table=table, query=query)\nexcept ValueError as e:\n    if 'only one of these' in str(e):\n        table = None  # prefer query\n        source = BigQuerySource(table=table, query=query)\n    else:\n        raise","preventionTips":["Build transform args from config with explicit mutually exclusive keys","Prefer query OR table in a single config field","Assert exactly one source is set in tests"],"tags":["python","apache-beam","bigquery","configuration","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}