apache/beam · error · ValueError

Only one of source_uris and source_stream may be specified…

Error message

Only one of source_uris and source_stream may be specified. Got both.

What it means

Raised by BigQueryWrapper._insert_load_job when both source_uris (GCS files) and source_stream (in-memory bytes) are provided. A BigQuery load job can ingest from a URI list or a stream, not both, so Beam rejects the conflicting input.

Solutions

  1. Set source_stream to None and load from GCS via source_uris.
  2. Or set source_uris to None/empty and load the in-memory stream.
  3. Add a check in your pipeline config so exactly one source is populated.
  4. If both inputs exist, first write the stream to GCS and then pass only source_uris.

Example fix

// before
wrapper._insert_load_job(job_ref, 'CSV', source_uris=uris, source_stream=data)

// after
wrapper._insert_load_job(job_ref, 'CSV', source_uris=uris, source_stream=None)
Defensive patterns

Strategy: validation

Validate before calling

if source_uris and source_stream:
    raise ValueError('choose one load source: GCS URIs or in-memory stream')

Type guard

def has_single_load_source(uris, stream):
    return bool(uris) != bool(stream)

Try / catch

try:
    wrapper.perform_load_job(..., source_uris=uris, source_stream=data)
except ValueError as e:
    if 'Only one of source_uris and source_stream' in str(e):
        choose_and_set_single_source()  # explicitly clear the other
    else:
        raise

Prevention

When it happens

Trigger: Calling _insert_load_job(..., source_uris=['gs://...'], source_stream=<bytes>) directly, or perform_load_job with both a file list and a stream configured by different code paths.

Common situations: Switching a pipeline from GCS-based loading to streaming loads and leaving the old URIs configured; fallback logic that sets both 'just in case'; template options where source URI list is non-empty by default.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/b2e30ee023aea2ae. Report an issue: GitHub.

Appendix: source

Thrown at sdks/python/apache_beam/io/gcp/bigquery_tools.py:556

      project_id,
      job_id,
      table_reference,
      source_uris=None,
      source_stream=None,
      schema=None,
      write_disposition=None,
      create_disposition=None,
      additional_load_parameters=None,
      source_format=None,
      job_labels=None):

    if not source_uris and not source_stream:
      _LOGGER.warning(
          'Both source URIs and source stream are not provided. BigQuery load '
          'job will not load any data.')

    if source_uris and source_stream:
      raise ValueError(
          'Only one of source_uris and source_stream may be specified. '
          'Got both.')

    if source_uris is None:
      source_uris = []

    additional_load_parameters = additional_load_parameters or {}
    job_schema = None if schema == 'SCHEMA_AUTODETECT' else schema
    reference = bigquery.JobReference(jobId=job_id, projectId=project_id)
    request = bigquery.BigqueryJobsInsertRequest(
        projectId=project_id,
        job=bigquery.Job(
            configuration=bigquery.JobConfiguration(
                load=bigquery.JobConfigurationLoad(
                    sourceUris=source_uris,
                    destinationTable=table_reference,
                    schema=job_schema,
                    writeDisposition=write_disposition,

View on GitHub (pinned to 12126d8942)