apache/beam · error · AttributeError

Error trying to access nonexistent attribute

Error message

Error trying to access nonexistent attribute `{key}` in write result. Please see __documentation__ for available attributes.

What it means

WriteResult.__getitem__ raises AttributeError when indexing with a key that is not in self.attributes, i.e. an attribute name no write method produces. It guards the dict-like access to the write result's attribute descriptors.

Solutions

  1. Use one of the documented attributes: destination, job_id, method, failed_rows, failed_rows_with_errors, destination_load_jobid_pairs, destination_copy_jobid_pairs, destination_file_prefix.
  2. Check `key in result.attributes` before indexing.
  3. Use attribute access with a valid property name instead of __getitem__.

Example fix

// before
print(result['job_ids'])
// after
print(result['destination_job_ids'])
Defensive patterns

Strategy: type-guard

Validate before calling

if key not in result.attributes:
    raise KeyError(f'{key} not available; valid: {list(result.attributes)}')

Type guard

def has_key(result, key):
    return key in result.attributes

Try / catch

try:
    value = result[key]
except AttributeError:
    value = None

Prevention

When it happens

Trigger: result['destination_load_jobids'] (typo) or result['some_custom_key'] on a WriteResult object.

Common situations: Misspelled attribute names (e.g. 'job_id' instead of 'destination_job_ids'); assuming arbitrary keys exist on the result.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

    Returns:
      A PCollection of rows that failed when inserting to BigQuery,
      along with their errors.

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

    return self._failed_rows_with_errors

  def __getitem__(self, key):
    if key not in self.attributes:
      raise AttributeError(
          f'Error trying to access nonexistent attribute `{key}` in write '
          'result. Please see __documentation__ for available attributes.')

    return self.attributes[key].__get__(self, WriteResult)


class StorageWriteToBigQuery(PTransform):
  """Writes data to BigQuery using Storage API.
  Supports dynamic destinations. Dynamic schemas are not supported yet.

  Experimental; no backwards compatibility guarantees.
  """
  IDENTIFIER = "beam:schematransform:org.apache.beam:bigquery_storage_write:v2"
  FAILED_ROWS = "FailedRows"
  FAILED_ROWS_WITH_ERRORS = "FailedRowsWithErrors"
  # fields for rows sent to Storage API with dynamic destinations
  DESTINATION = "destination"
  RECORD = "record"

View on GitHub (pinned to 12126d8942)