apache/beam · error · AttributeError

Cannot get because it is not produced by the write method…

Error message

Cannot get {attribute} because it is not produced by the {self._method} write method. Note: only {valid_methods} produces this attribute.

What it means

WriteResult.validate() raises AttributeError when reading a result attribute (e.g. destination_job_ids) that is only produced by certain write methods, but the WriteResult came from a different method (e.g. STREAMING_INSERTS). Each write method produces a distinct subset of result attributes.

Solutions

  1. Check result.method before accessing method-specific attributes.
  2. Only access load-job attributes (destination_load_jobid_pairs, destination_copy_jobid_pairs, destination_file_prefix) when using BigQueryBatchFileLoads/FILE_LOADS.
  3. Restructure code to use attribute sets valid for the method actually used.

Example fix

// before
result = t | WriteToBigQuery(..., method='STREAMING_INSERTS')
print(result.destination_load_jobid_pairs)
// after
if result.method == WriteToBigQuery.Method.FILE_LOADS:
  print(result.destination_load_jobid_pairs)
Defensive patterns

Strategy: try-catch

Validate before calling

if result.method in (WriteToBigQuery.Method.FILE_LOADS,):
    job_ids = result.destination_load_jobid_pairs

Type guard

def has_load_attrs(result):
    return result.method in (WriteToBigQuery.Method.FILE_LOADS,)

Try / catch

try:
    pairs = result.destination_load_jobid_pairs
except AttributeError:
    pairs = None  # method doesn't produce load job ids

Prevention

When it happens

Trigger: Calling result.destination_load_jobid_pairs, destination_file_prefix, or destination_copy_jobid_pairs on a WriteResult whose method is STREAMING_INSERTS or STORAGE_WRITE_API.

Common situations: Generic pipeline code that inspects write results regardless of which write method was configured; switching write methods without updating post-write reporting code.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sdks/python/apache_beam/io/gcp/bigquery.py:2612

    self._failed_rows = failed_rows
    self._failed_rows_with_errors = failed_rows_with_errors

    from apache_beam.io.gcp.bigquery_file_loads import BigQueryBatchFileLoads
    self.attributes = {
        BigQueryWriteFn.FAILED_ROWS: WriteResult.failed_rows,
        BigQueryWriteFn.FAILED_ROWS_WITH_ERRORS: WriteResult.
        failed_rows_with_errors,
        BigQueryBatchFileLoads.DESTINATION_JOBID_PAIRS: WriteResult.
        destination_load_jobid_pairs,
        BigQueryBatchFileLoads.DESTINATION_FILE_PAIRS: WriteResult.
        destination_file_pairs,
        BigQueryBatchFileLoads.DESTINATION_COPY_JOBID_PAIRS: WriteResult.
        destination_copy_jobid_pairs,
    }

  def validate(self, valid_methods, attribute):
    if self._method not in valid_methods:
      raise AttributeError(
          f'Cannot get {attribute} because it is not produced '
          f'by the {self._method} write method. Note: only '
          f'{valid_methods} produces this attribute.')

  @property
  def destination_load_jobid_pairs(
      self) -> PCollection[tuple[str, JobReference]]:
    """A ``FILE_LOADS`` method attribute

    Returns: A PCollection of the table destinations that were successfully
      loaded to using the batch load API, along with the load job IDs.

    Raises: AttributeError: if accessed with a write method
    besides ``FILE_LOADS``."""
    self.validate([WriteToBigQuery.Method.FILE_LOADS],
                  'DESTINATION_JOBID_PAIRS')

    return self._destination_load_jobid_pairs

View on GitHub (pinned to 12126d8942)