{"record":{"id":"84d526b7caf31826","repo":"apache/iceberg","slug":"cannot-create-namespace-s-ref-s-is-no-longe","errorCode":null,"errorMessage":"Cannot create namespace '%s': ref '%s' is no longer valid.","messagePattern":"Cannot create namespace '(.+?)': ref '(.+?)' is no longer valid\\.","errorType":"exception","errorClass":"UncheckedIOException","httpStatus":500,"severity":"error","filePath":"nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java","lineNumber":255,"sourceCode":"                    Conflict.ConflictType.KEY_EXISTS, Conflict.ConflictType.NAMESPACE_ABSENT));\n        if (conflict.isPresent()) {\n          switch (conflict.get().conflictType()) {\n            case KEY_EXISTS:\n              Content conflicting = withReference(api.getContent()).key(key).get().get(key);\n              throw namespaceAlreadyExists(key, conflicting, e);\n            case NAMESPACE_ABSENT:\n              throw new NoSuchNamespaceException(\n                  e,\n                  \"Cannot create namespace '%s': parent namespace '%s' does not exist\",\n                  namespace,\n                  conflict.get().key());\n          }\n        }\n        throw new RuntimeException(\n            String.format(\"Cannot create namespace '%s': %s\", namespace, e.getMessage()));\n      }\n    } catch (NessieNotFoundException e) {\n      throw new UncheckedIOException(\n          String.format(\n              \"Cannot create namespace '%s': ref '%s' is no longer valid.\",\n              namespace, getRef().getName()),\n          e);\n    } catch (BaseNessieClientServerException e) {\n      throw new UncheckedIOException(\n          String.format(\"Cannot create namespace '%s': %s\", namespace, e.getMessage()), e);\n    }\n  }\n\n  public List<Namespace> listNamespaces(Namespace namespace) throws NoSuchNamespaceException {\n    try {\n      String filter = \"entry.contentType == 'NAMESPACE' && \";\n      if (namespace.isEmpty()) {\n        filter += \"size(entry.keyElements) == 1\";\n      } else {\n        org.projectnessie.model.Namespace root =\n            org.projectnessie.model.Namespace.of(namespace.levels());","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/nessie/src/main/java/org/apache/iceberg/nessie/NessieIcebergClient.java#L237-L273","documentation":"NessieIcebergClient.createNamespace commits a namespace content object to the currently pinned Nessie reference. Before committing it fetches existing content against that reference; if the reference has been deleted (or renamed) server-side, the Nessie API raises NessieNotFoundException, which is rethrown as an UncheckedIOException stating the ref is no longer valid. The reference object held client-side is stale relative to the server state.","triggerScenarios":"Calling Catalog.createNamespace on a Nessie catalog whose configured branch/tag (e.g. via ref= or branch URI parameter) was deleted or recreated (hash moved) by another client between when the catalog was configured and when createNamespace ran.","commonSituations":"CI pipelines or another developer deleted/recreated the working branch; a Spark/Flink job pinned to a branch that was dropped; the default branch was renamed; stale catalog instance cached across long-running sessions.","solutions":["Verify the reference exists on the Nessie server (REST GET /trees or Nessie CLI 'branch list') and recreate it if deleted.","Re-create the Iceberg catalog / NessieCatalog instance so it re-resolves the reference to the current HEAD hash.","If the branch was intentionally recreated, point the catalog at the new branch name via the 'ref' catalog property.","Use a mutable default branch and avoid deleting branches that live jobs are pinned to."],"exampleFix":"// before\nMap<String, String> conf = Map.of(\n    CatalogProperties.URI, \"http://nessie:19120/api/v1\",\n    CatalogProperties.CATALOG_IMPL, NessieCatalog.class.getName(),\n    NessieUtil.NESSIE_CLIENT_AUTH, token);\n// pin ref that was later deleted\nconf.put(\"ref\", \"feature-x\"); // feature-x no longer exists -> error\n// after\nList<Reference> refs = api.getAllReferences().get().getReferences();\nboolean exists = refs.stream().anyMatch(r -> r.getName().equals(\"feature-x\"));\nconf.put(\"ref\", exists ? \"feature-x\" : \"main\"); // guard before building catalog","handlingStrategy":"try-catch","validationCode":"boolean refExists = api.getAllReferences().get().getReferences().stream()\n    .anyMatch(r -> r.getName().equals(expectedRef));","typeGuard":null,"tryCatchPattern":"try {\n  catalog.createNamespace(ns);\n} catch (UncheckedIOException e) {\n  if (e.getMessage().contains(\"no longer valid\")) {\n    // recreate/re-resolve ref, rebuild catalog, retry once\n  } else throw e;\n}","preventionTips":["Do not delete/recreate branches that long-running jobs are pinned to.","Resolve the ref fresh (rebuild catalog) instead of caching catalog instances across branch mutations.","Monitor Nessie branch lifecycle in CI to avoid racing running jobs."],"tags":["nessie","namespace","stale-reference","git-like-catalog"],"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-14T11:17:12.474Z"}