apache/beam · error · io.UnsupportedOperation
JsonRowWriter is not readable
Error message
JsonRowWriter is not readable
What it means
JsonRowWriter wraps a file opened for writing JSON rows for BigQuery loads; its read() raises io.UnsupportedOperation('JsonRowWriter is not readable') because a write-only writer cannot serve reads. It signals an attempt to read from a stream that only supports writing.
Solutions
- Reopen the underlying file path with open(path, 'rb') (or the reader class) to read the written JSON records
- Use the corresponding reader (e.g. JsonReader) instead of the writer
- Access writer._file_handle only if you know it's opened in a read-capable mode
- Restructure code so reading happens after closing the writer, on a fresh handle
Example fix
// before
rows = writer.read() # raises UnsupportedOperation
// after
writer.flush()
with open(writer._file_handle.name, 'r') as f:
rows = [json.loads(line) for line in f] Defensive patterns
Strategy: try-catch
Validate before calling
if getattr(obj, 'writable', lambda: False)() and not getattr(obj, 'readable', lambda: True)():
raise TypeError('stream is write-only; reopen the 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, 'r') as f:
data = f.read() Prevention
- Treat *RowWriter objects as write-only by contract
- Read back via the matching reader class or by reopening the file path
- Check .readable() before calling read() on any file-like object
- Close the writer before reading its output
When it happens
Trigger: Calling .read() (or passing the writer where a readable file-like object is expected) on a JsonRowWriter instance; e.g. mistakenly handing the writer to code that reads records back.
Common situations: Confusing the writer with the reader class; code written for a real file object reused on the writer; debugging code attempting to inspect written contents directly from the writer instead of reopening 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
- AvroRowWriter is not readable
- Output stream must be writable
- Please specify a BigQuery table to read from.
- A BigQuery table or a query must be specified
- A schema is required to write non-schema'd data.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1097e16c870bf3d3.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/io/gcp/bigquery_tools.py:1487
"""
if not file_handle.writable():
raise ValueError("Output stream must be writable")
self._file_handle = file_handle
self._coder = RowAsDictJsonCoder()
def close(self):
self._file_handle.close()
@property
def closed(self):
return self._file_handle.closed
def flush(self):
self._file_handle.flush()
def read(self, size=-1):
raise io.UnsupportedOperation("JsonRowWriter is not readable")
def tell(self):
return self._file_handle.tell()
def writable(self):
return self._file_handle.writable()
def write(self, row):
return self._file_handle.write(self._coder.encode(row) + b'\n')
class AvroRowWriter(io.IOBase):
"""
A writer which provides an IOBase-like interface for writing table rows
(represented as dicts) as Avro records.
"""
def __init__(self, file_handle, schema):
"""Initialize an AvroRowWriter.View on GitHub (pinned to 12126d8942)