{"record":{"id":"030b15002bbd602d","repo":"apache/iceberg","slug":"cannot-apply-unknown-wap-id-s-030b15","errorCode":null,"errorMessage":"Cannot apply unknown WAP ID '%s'","messagePattern":"Cannot apply unknown 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":112,"sourceCode":"\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        });\n  }\n\n  @Override\n  public String name() {\n    return NAME;\n  }\n\n  @Override\n  public String description() {\n    return \"ApplyWapChangesProcedure\";","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/procedures/PublishChangesProcedure.java#L94-L130","documentation":"PublishChangesProcedure looks up the staged snapshot with the given WAP ID and cherry-picks it. If no snapshot in the table carries that staged WAP ID, publishing cannot proceed and this ValidationException is thrown.","triggerScenarios":"Calling publish_changes with a wap_id that matches no snapshot's staged WAP ID — e.g. the write with spark.wap.id failed, the snapshots were expired, or a wrong ID was passed.","commonSituations":"Typos in the WAP ID; writer job failed before committing the staged snapshot; snapshots table retained less than expected so staged snapshots were expired; forgetting to set spark.wap.id on the writer (so nothing was staged).","solutions":["Verify staged snapshots via SELECT * FROM table.snapshots WHERE summary['wap.id'] IS NOT NULL and use an existing ID.","Re-run the write job with spark.wap.id set before publishing.","Check snapshot expiration settings — increase retention so staged snapshots survive until publish."],"exampleFix":"// before\ncall publish_changes(table => 'db.t', wap_id => 'wap-123')\n// after\n-- find real id first: SELECT snapshot_id, summary['wap.id'] FROM db.t.snapshots\ncall publish_changes(table => 'db.t', wap_id => 'wap-abc')","handlingStrategy":"validation","validationCode":"val staged = spark.table(s\"$t.snapshots\")\n  .filter(col(\"summary.wap.id\") === wapId)\nrequire(staged.count() == 1, s\"WAP ID $wapId not staged (or ambiguous)\")","typeGuard":null,"tryCatchPattern":"try {\n  spark.sql(s\"CALL cat.system.publish_changes(table => '$t', wap_id => '$id')\")\n} catch {\n  case e: Exception if e.getMessage.contains(\"unknown WAP ID\") =>\n    logger.error(\"Staged snapshot missing; re-run the writer job\")\n}","preventionTips":["Confirm the writer job committed before publishing","Use SELECT ... snapshots to copy the exact wap.id","Keep snapshot retention long enough to cover staged snapshots"],"tags":["spark","wap","snapshot"],"backgroundTag":"resource-not-found","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"}