{"record":{"id":"4f6323d4704d498a","repo":"apache/beam","slug":"s-s","errorCode":null,"errorMessage":"%s. %s","messagePattern":"%s\\. %s","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/gcp/bigquery.py","lineNumber":575,"sourceCode":"    if self.table_schema:\n      self.field_names = tuple(fs.name for fs in self.table_schema.fields)\n      self.field_types = tuple(fs.type for fs in self.table_schema.fields)\n\n  def encode(self, table_row):\n    if self.table_schema is None:\n      raise AttributeError(\n          'The TableRowJsonCoder requires a table schema for '\n          'encoding operations. Please specify a table_schema argument.')\n    try:\n      return json.dumps(\n          collections.OrderedDict(\n              zip(\n                  self.field_names,\n                  [from_json_value(f.v) for f in table_row.f])),\n          allow_nan=False,\n          default=bigquery_tools.default_encoder)\n    except ValueError as e:\n      raise ValueError('%s. %s' % (e, bigquery_tools.JSON_COMPLIANCE_ERROR))\n\n  def decode(self, encoded_table_row):\n    od = json.loads(\n        encoded_table_row, object_pairs_hook=collections.OrderedDict)\n    return bigquery.TableRow(\n        f=[bigquery.TableCell(v=to_json_value(e)) for e in od.values()])\n\n\nclass BigQueryDisposition(object):\n  \"\"\"Class holding standard strings used for create and write dispositions.\"\"\"\n\n  CREATE_NEVER = 'CREATE_NEVER'\n  CREATE_IF_NEEDED = 'CREATE_IF_NEEDED'\n  WRITE_TRUNCATE = 'WRITE_TRUNCATE'\n  WRITE_APPEND = 'WRITE_APPEND'\n  WRITE_EMPTY = 'WRITE_EMPTY'\n\n  @staticmethod","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/gcp/bigquery.py#L557-L593","documentation":"When encoding a TableRow to JSON, json.dumps raised ValueError (e.g. NaN/Infinity values, since allow_nan=False). The error is re-raised with the original message plus a note that BigQuery JSON must be compliant (no NaN/Infinity).","triggerScenarios":"Encoding a TableRow whose cell values contain NaN, Infinity, or otherwise non-JSON-compliant values, in TableRowJsonCoder.encode.","commonSituations":"Pipeline data computed with floats producing NaN/inf (division by zero, missing fills) that is then written to BigQuery as JSON rows.","solutions":["Clean the data before writing: replace NaN/inf with None (beam.Map with math.isfinite check)","Use to_json_value from bigquery_tools or convert non-compliant floats to strings","Set a CoGroup/filter step to drop or fix offending records"],"exampleFix":"// before\n# row.f contains float('nan')\nencoded = coder.encode(row)\n// after\nimport math\nclean = [None if isinstance(v, float) and not math.isfinite(v) else v for v in values]\nrow = TableRow(f=[TableCell(v=v) for v in clean])","handlingStrategy":"validation","validationCode":"import math\ndef row_is_json_safe(row):\n    return all(not isinstance(c.v, float) or math.isfinite(c.v) for c in row.f)\nassert row_is_json_safe(row), 'row contains NaN/Infinity'","typeGuard":"def is_json_safe(v):\n    return not (isinstance(v, float) and not math.isfinite(v))","tryCatchPattern":"try:\n    encoded = coder.encode(row)\nexcept ValueError as e:\n    if 'JSON_COMPLIANCE' in str(e) or 'Out of range float' in str(e):\n        row = sanitize_row(row)  # map non-finite floats to None\n        encoded = coder.encode(row)\n    else:\n        raise","preventionTips":["Sanitize floats (fillna, replace inf) upstream in the pipeline","Add a DoFn/filter asserting json-compliance before the sink","Enable allow_nan=False checks in local tests"],"tags":["python","apache-beam","bigquery","json","data-quality"],"backgroundTag":"json-serialization-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}