{"record":{"id":"9152f6189ab5efe7","repo":"apache/iceberg","slug":"cannot-delete-non-empty-namespace-s","errorCode":null,"errorMessage":"Cannot delete non-empty namespace %s","messagePattern":"Cannot delete non-empty namespace (.+?)","errorType":"exception","errorClass":"NamespaceNotEmptyException","httpStatus":409,"severity":"error","filePath":"aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java","lineNumber":284,"sourceCode":"                .tableName(awsProperties.dynamoDbTableName())\n                .consistentRead(true)\n                .key(namespacePrimaryKey(namespace))\n                .build());\n\n    if (!response.hasItem()) {\n      throw new NoSuchNamespaceException(\"Cannot find namespace %s\", namespace);\n    }\n\n    return response.item().entrySet().stream()\n        .filter(e -> isProperty(e.getKey()))\n        .collect(Collectors.toMap(e -> toPropertyKey(e.getKey()), e -> e.getValue().s()));\n  }\n\n  @Override\n  public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyException {\n    validateNamespace(namespace);\n    if (!listTables(namespace).isEmpty()) {\n      throw new NamespaceNotEmptyException(\"Cannot delete non-empty namespace %s\", namespace);\n    }\n\n    try {\n      dynamo.deleteItem(\n          DeleteItemRequest.builder()\n              .tableName(awsProperties.dynamoDbTableName())\n              .key(namespacePrimaryKey(namespace))\n              .conditionExpression(\"attribute_exists(\" + COL_NAMESPACE + \")\")\n              .build());\n      return true;\n    } catch (ConditionalCheckFailedException e) {\n      return false;\n    }\n  }\n\n  @Override\n  public boolean setProperties(Namespace namespace, Map<String, String> properties)\n      throws NoSuchNamespaceException {","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/aws/src/main/java/org/apache/iceberg/aws/dynamodb/DynamoDbCatalog.java#L266-L302","documentation":"DynamoDbCatalog.dropNamespace() refuses to drop a namespace that still contains tables, throwing NamespaceNotEmptyException with this message. Before deleting the namespace item it calls listTables(namespace); any result blocks the drop, protecting tables from being orphaned.","triggerScenarios":"Calling catalog.dropNamespace(namespace) when listTables(namespace) returns at least one table registered under that namespace in the DynamoDB catalog table.","commonSituations":"Cleanup scripts that drop namespaces without dropping child tables first; partially failed teardown leaving orphaned table rows; nested namespaces where tables exist under a deeper level sharing the same partition key prefix.","solutions":["List and drop all tables in the namespace first: for (TableIdentifier t : catalog.listTables(namespace)) catalog.dropTable(t); then retry dropNamespace.","If the rows are known orphans, remove the stale table items from the DynamoDB catalog table, then retry the drop.","Catch org.apache.iceberg.exceptions.NamespaceNotEmptyException if the caller intentionally skips non-empty namespaces."],"exampleFix":"// before\ncatalog.dropNamespace(Namespace.of(\"staging\"));\n\n// after\nfor (TableIdentifier t : catalog.listTables(Namespace.of(\"staging\"))) {\n  catalog.dropTable(t);\n}\ncatalog.dropNamespace(Namespace.of(\"staging\"));","handlingStrategy":"validation","validationCode":"Namespace ns = Namespace.of(\"staging\");\nif (!catalog.listTables(ns).isEmpty()) {\n  throw new IllegalStateException(\"Refusing to drop non-empty namespace \" + ns);\n}\ncatalog.dropNamespace(ns);","typeGuard":null,"tryCatchPattern":"try {\n  catalog.dropNamespace(ns);\n} catch (NamespaceNotEmptyException e) {\n  catalog.listTables(ns).forEach(t -> catalog.dropTable(t));\n  catalog.dropNamespace(ns);\n}","preventionTips":["Always drain tables before dropping namespaces in teardown scripts","Run orphan-row cleanup for the DynamoDB catalog table periodically","Check nested namespace levels for tables sharing the partition key prefix"],"tags":["aws","dynamodb","catalog","namespace-not-empty"],"backgroundTag":"unsupported-operation","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"}