{"record":{"id":"c379747801682ad8","repo":"apache/beam","slug":"document-id-field-documentidfield-must-be-set-on-input-rows","errorCode":null,"errorMessage":"Document id field '{documentIdField}' must be set on input rows.","messagePattern":"Document id field '(.+?)' must be set on input rows\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java","lineNumber":83,"sourceCode":"    for (Map.Entry<String, Value> entry : document.getFieldsMap().entrySet()) {\n      values.put(entry.getKey(), valueToJava(entry.getValue()));\n    }\n    if (documentIdField != null && schema.hasField(documentIdField)) {\n      values.put(documentIdField, documentIdFromName(document.getName()));\n    }\n    return toRow(values, schema);\n  }\n\n  static Document rowToDocument(\n      Row row,\n      Schema schema,\n      String projectId,\n      String databaseId,\n      String collectionId,\n      String documentIdField) {\n    String documentId = row.getString(documentIdField);\n    if (documentId == null || documentId.isEmpty()) {\n      throw new IllegalArgumentException(\n          \"Document id field '\" + documentIdField + \"' must be set on input rows.\");\n    }\n\n    Document.Builder builder =\n        Document.newBuilder()\n            .setName(documentPath(projectId, databaseId, collectionId, documentId));\n    for (Field field : schema.getFields()) {\n      String fieldName = field.getName();\n      if (fieldName.equals(documentIdField)) {\n        continue;\n      }\n      Object fieldValue = row.getValue(fieldName);\n      if (fieldValue != null) {\n        builder.putFields(fieldName, javaToValue(fieldValue, field.getType()));\n      }\n    }\n    return builder.build();\n  }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java#L65-L101","documentation":"rowToDocument builds a Firestore Document from a Beam Row and requires the document ID to be present in the row under the configured documentIdField column. It throws IllegalArgumentException when that field is null or the empty string, because the document path cannot be constructed without an ID.","triggerScenarios":"Writing Rows via the Firestore IO connector when the row's value at row.getString(documentIdField) is null or \"\" — e.g. the documentIdField option names a field the schema doesn't populate, or upstream transforms left it unset.","commonSituations":"Misconfigured documentIdField name (typo or field added after schema evolution); a source query that doesn't select the ID column; rows produced from a merge/join where the ID field is nullable and missing for some records.","solutions":["Ensure every input Row has a non-empty string in the documentIdField column before writing","Verify the documentIdField option matches the exact schema field name (case-sensitive)","Populate the ID field upstream with a map transform if the source doesn't provide it","Filter out or repair rows with null/empty IDs before the write"],"exampleFix":"// before\nRow row = Row.withSchema(schema).addValues(null, \"Alice\").build(); // id field null\n// after\nRow row = Row.withSchema(schema).addValues(\"user42\", \"Alice\").build(); // id populated\n// or guard upstream:\nrows.apply(Filter.by(r -> r.getString(\"id\") != null && !r.getString(\"id\").isEmpty()))","handlingStrategy":"validation","validationCode":"if (row.getSchema().getFieldNames().contains(documentIdField)\n    && row.getString(documentIdField) != null\n    && !row.getString(documentIdField).isEmpty()) {\n  firestoreIo.write(row);\n}","typeGuard":null,"tryCatchPattern":"try {\n  return FirestoreUtils.rowToDocument(row, projectId, databaseId, collectionId, documentIdField);\n} catch (IllegalArgumentException e) {\n  log.error(\"Row missing document id field '{}': {}\", documentIdField, row); \n  throw e;\n}","preventionTips":["Filter null/empty IDs before the write transform","Keep the documentIdField name in a shared constant to avoid typos","Add a unit test asserting every produced Row has a non-empty ID"],"tags":["java","apache-beam","firestore","schema-validation"],"backgroundTag":"empty-required-field","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"}