{"record":{"id":"cf31ebcde261cfed","repo":"apache/iceberg","slug":"cannot-apply-non-unique-wap-id-found-multiple-sna-cf31eb","errorCode":null,"errorMessage":"Cannot apply non-unique WAP ID. Found multiple snapshots with WAP ID '%s'","messagePattern":"Cannot apply non-unique WAP ID\\. Found multiple snapshots with WAP ID '(.+?)'","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/procedures/PublishChangesProcedure.java","lineNumber":102,"sourceCode":"  public ProcedureParameter[] parameters() {\n    return PARAMETERS;\n  }\n\n  @Override\n  public Iterator<Scan> call(InternalRow args) {\n    ProcedureInput input = new ProcedureInput(spark(), tableCatalog(), PARAMETERS, args);\n\n    Identifier tableIdent = input.ident(TABLE_PARAM);\n    String wapId = input.asString(WAP_ID_PARAM);\n\n    return modifyIcebergTable(\n        tableIdent,\n        table -> {\n          Snapshot matchingSnap = null;\n          for (Snapshot snap : table.snapshots()) {\n            if (wapId.equals(WapUtil.stagedWapId(snap))) {\n              if (matchingSnap != null) {\n                throw new ValidationException(\n                    \"Cannot apply non-unique WAP ID. Found multiple snapshots with WAP ID '%s'\",\n                    wapId);\n              } else {\n                matchingSnap = snap;\n              }\n            }\n          }\n\n          if (matchingSnap == null) {\n            throw new ValidationException(\"Cannot apply unknown WAP ID '%s'\", wapId);\n          }\n\n          long wapSnapshotId = matchingSnap.snapshotId();\n          table.manageSnapshots().cherrypick(wapSnapshotId).commit();\n          Snapshot currentSnapshot = table.currentSnapshot();\n          InternalRow outputRow = newInternalRow(wapSnapshotId, currentSnapshot.snapshotId());\n          return asScanIterator(OUTPUT_TYPE, outputRow);\n        });","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/procedures/PublishChangesProcedure.java#L84-L120","documentation":"PublishChangesProcedure promotes a staged (WAP) snapshot written with a spark.wap.id to the table's current state via cherry-pick. WAP IDs must uniquely identify one staged snapshot; if two snapshots carry the same staged WAP ID, publishing is ambiguous and this ValidationException is thrown.","triggerScenarios":"Calling call publish_changes(table => ..., wap_id => 'X') when table.snapshots() contains more than one snapshot whose staged WAP ID equals 'X'.","commonSituations":"Reusing the same spark.wap.id across multiple writes without publishing in between; a retry job that re-wrote data with the same hard-coded WAP ID.","solutions":["Ensure each write uses a unique spark.wap.id (generate a UUID per write job).","Expire or delete the duplicate staged snapshots so only one has the target WAP ID, then retry publish_changes.","List snapshots to find duplicates (SELECT * FROM table.snapshots) and publish the correct one after cleanup."],"exampleFix":"// before\nspark.conf.set(\"spark.wap.id\", \"wap-123\") // reused in two jobs\n// after\nspark.conf.set(\"spark.wap.id\", java.util.UUID.randomUUID().toString())","handlingStrategy":"validation","validationCode":"val dupes = spark.table(s\"$t.snapshots\")\n  .filter(col(\"summary.wap.id\") === wapId).count()\nrequire(dupes <= 1, s\"$wapId used by $dupes staged snapshots\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate a unique spark.wap.id (UUID) per write job","Publish staged snapshots promptly before reuse","Audit snapshots table for duplicate wap.id values"],"tags":["spark","wap","snapshot"],"backgroundTag":"invalid-state-transition","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}