{"record":{"id":"4dc6b6b503748eb1","repo":"apache/beam","slug":"a-schema-is-required-in-order-to-prepare-rows-for-writing","errorCode":null,"errorMessage":"A schema is required in order to prepare rows for writing with STORAGE_WRITE_API.","messagePattern":"A schema is required in order to prepare rows for writing with STORAGE_WRITE_API\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":2763,"sourceCode":"    self.additional_bq_parameters = additional_bq_parameters\n    self._triggering_frequency = triggering_frequency\n    self._use_at_least_once = use_at_least_once\n    self._with_auto_sharding = with_auto_sharding\n    self._num_storage_api_streams = num_storage_api_streams\n    self._use_cdc_writes = use_cdc_writes\n    self._primary_key = primary_key\n    self._big_lake_configuration = big_lake_configuration\n    self._type_overrides = type_overrides\n    self._expansion_service = expansion_service or BeamJarExpansionService(\n        'sdks:java:io:google-cloud-platform:expansion-service:build')\n\n  def expand(self, input):\n    if self._schema is None:\n      try:\n        schema = schema_from_element_type(input.element_type)\n        is_rows = True\n      except TypeError as exn:\n        raise ValueError(\n            \"A schema is required in order to prepare rows \"\n            \"for writing with STORAGE_WRITE_API.\") from exn\n    elif callable(self._schema):\n      raise NotImplementedError(\n          \"Writing with dynamic schemas is not \"\n          \"supported for this write method.\")\n    elif isinstance(self._schema, vp.ValueProvider):\n      schema = self._schema.get()\n      is_rows = False\n    else:\n      schema = self._schema\n      is_rows = False\n\n    table = bigquery_tools.get_hashable_destination(self._table)\n\n    # if writing to one destination, just convert to Beam rows and send over\n    if not callable(table):\n      if is_rows:","sourceCodeStart":2745,"sourceCodeEnd":2781,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L2745-L2781","documentation":"StorageWriteToBigQuery.expand() requires a schema: if none was supplied and none can be inferred from the element type (schema_from_element_type raises TypeError), it re-raises as ValueError. The Storage Write API needs a proto/schema to encode rows.","triggerScenarios":"WriteToBigQuery(method=STORAGE_WRITE_API) with schema=None on a PCollection of plain dicts (no Beam schema registered).","commonSituations":"Streaming pipelines of untyped dict rows switched to STORAGE_WRITE_API; forgetting to define a Beam schema on the element type.","solutions":["Pass an explicit schema argument to WriteToBigQuery.","Use typed elements (Beam Rows / namedtuples) or apply a schema via apache_beam.pvalue.AsSchema / beam.Map to a schema'd type.","Ensure element type is not untyped dict before the write."],"exampleFix":"// before\nrows | WriteToBigQuery(table='proj:ds.tbl', method='STORAGE_WRITE_API')\n// after\nrows | WriteToBigQuery(table='proj:ds.tbl', method='STORAGE_WRITE_API', schema='id:STRING,value:FLOAT')","handlingStrategy":"validation","validationCode":"from apache_beam.typehints.schemas import schema_from_element_type\ntry:\n    schema_from_element_type(pcoll.element_type)\nexcept TypeError:\n    pass  # need explicit schema","typeGuard":null,"tryCatchPattern":"try:\n    result = (rows | WriteToBigQuery(method='STORAGE_WRITE_API'))\nexcept ValueError as e:\n    if 'schema is required' in str(e):\n        result = (rows | WriteToBigQuery(method='STORAGE_WRITE_API', schema=my_schema))","preventionTips":["Attach a Beam schema to your elements before STORAGE_WRITE_API writes.","Always pass schema explicitly for Storage API writes."],"tags":["apache-beam","bigquery","storage-write-api","missing-schema"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}