apache/beam · error · io.UnsupportedOperation

AvroRowWriter is not readable

Error message

AvroRowWriter is not readable

What it means

AvroRowWriter wraps a write-only stream feeding a fastavro Writer for BigQuery Avro loads; its read() raises io.UnsupportedOperation('AvroRowWriter is not readable') because the writer cannot serve reads. It signals reading from a write-only writer.

Solutions

  1. Close/flush the writer and reopen the file (or use the matching Avro reader) to read records back
  2. Pass a separately-opened readable handle to APIs that need to read
  3. Check whether the object is a writer (writable() is True) before calling read()
  4. Restructure to write fully, close, then read in a second phase

Example fix

// before
with writer:
    write_rows(writer)
    data = writer.read()  # raises UnsupportedOperation
// after
with writer:
    write_rows(writer)
writer.flush()
with open(writer._file_handle.name, 'rb') as f:
    data = f.read()
Defensive patterns

Strategy: type-guard

Validate before calling

if not obj.readable():
    raise TypeError('write-only stream: reopen the underlying file to read')

Type guard

def is_readable_stream(o):
    return hasattr(o, 'read') and callable(getattr(o, 'readable', None)) and o.readable()

Try / catch

try:
    data = writer.read()
except io.UnsupportedOperation:
    writer.flush()
    with open(writer._file_handle.name, 'rb') as f:
        data = f.read()

Prevention

When it happens

Trigger: Calling .read() on an AvroRowWriter, or passing it to an API expecting a readable file-like object (e.g. uploading via a read handle).

Common situations: Passing the writer to Beam/GCS code that opens its own readable handle; confusing AvroRowWriter with an AvroReader; attempting to verify written Avro bytes by reading from the writer instead of the file.

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/0407de7e50eab7e4. Report an issue: GitHub.

Appendix: source

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

  def close(self):
    if not self._file_handle.closed:
      self.flush()
      self._file_handle.close()

  @property
  def closed(self):
    return self._file_handle.closed

  def flush(self):
    if self._file_handle.closed:
      raise ValueError("flush on closed file")

    self._avro_writer.flush()
    self._file_handle.flush()

  def read(self, size=-1):
    raise io.UnsupportedOperation("AvroRowWriter is not readable")

  def tell(self):
    # Flush the fastavro Writer to the underlying stream, otherwise there isn't
    # a reliable way to determine how many bytes have been written.
    self._avro_writer.flush()
    return self._file_handle.tell()

  def writable(self):
    return self._file_handle.writable()

  def write(self, row):
    try:
      self._avro_writer.write(row)
    except (TypeError, ValueError) as ex:
      _, _, tb = sys.exc_info()
      raise ex.__class__(
          "Error writing row to Avro: {}\nSchema: {}\nRow: {}".format(
              ex, self._avro_writer.schema, row)).with_traceback(tb)

View on GitHub (pinned to 12126d8942)