{"record":{"id":"2f6d916ad1f10b50","repo":"apache/iceberg","slug":"cannot-apply-unknown-wap-id-wapid","errorCode":null,"errorMessage":"Cannot apply unknown WAP ID '${wapId}'","messagePattern":"Cannot apply unknown WAP ID '(.+?)'","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/procedures/PublishChangesProcedure.java","lineNumber":107,"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 new InternalRow[] {outputRow};\n        });\n  }\n\n  @Override\n  public String description() {\n    return \"ApplyWapChangesProcedure\";\n  }\n}\n","sourceCodeStart":89,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/procedures/PublishChangesProcedure.java#L89-L123","documentation":"publish_changes scans all table snapshots for one whose wap-id property equals the supplied wap_id argument. If none matches, it throws ValidationException — no staged snapshot exists under that ID to publish.","triggerScenarios":"Calling `CALL cat.system.publish_changes(wap_id => 'xyz')` where no snapshot has property wap-id='xyz' — the staged write never committed, failed, was already published, or the ID string differs (case/whitespace).","commonSituations":"Copy-pasting WAP IDs between jobs; write job failure before commit; expire_snapshots removing the staged snapshot; typos in the wap_id argument.","solutions":["Check staged snapshots via the snapshots metadata table for the exact wap-id value.","Confirm the write job actually committed with wap staging enabled (spark.wap.enabled=true).","Re-run the staged write to create the snapshot, then publish with the exact ID.","If snapshots were expired, republish from a fresh staged write."],"exampleFix":"// before\nspark.sql(\"CALL cat.system.publish_changes(wap_id => 'run-42')\") // no such staged snapshot\n// after\n// verify staged snapshot exists in cat.db.t.snapshots with wap-id='run-42' first\nspark.sql(\"CALL cat.system.publish_changes(wap_id => 'run-42')\")","handlingStrategy":"validation","validationCode":"long matches = spark.read().format(\"iceberg\").load(\"cat.db.t.snapshots\")\n    .filter(\"snapshot_props['wap-id'] = '\" + wapId + \"'\").count();\nif (matches == 0) throw new IllegalStateException(\"Unknown WAP ID: \" + wapId);","typeGuard":null,"tryCatchPattern":"try { spark.sql(\"CALL cat.system.publish_changes(wap_id => '\" + wapId + \"')\"); } catch (ValidationException e) { if (e.getMessage().contains(\"unknown WAP ID\")) { /* verify staged write committed, then retry with correct ID */ } throw e; }","preventionTips":["Pass the exact spark.wap.id value from the write job to publish_changes.","Confirm the staged write committed successfully before publishing.","Remember expire_snapshots can remove staged snapshots; publish promptly.","Log the WAP ID from the writer and reuse it verbatim."],"tags":["spark","procedures","wap","snapshot","not-found"],"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"}