{"record":{"id":"ab046d499d6486b0","repo":"apache/cassandra","slug":"cannot-drop-user-type-s-s-as-it-is-still-used-ab046d","errorCode":null,"errorMessage":"Cannot drop user type '%s.%s' as it is still used by user types %s","messagePattern":"Cannot drop user type '(.+?)\\.(.+?)' as it is still used by user types (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/DropTypeStatement.java","lineNumber":105,"sourceCode":"         * definition with the previous name still in use, things can get messy).\n         * We have three places to check:\n         * 1) UDFs and UDAs using the type\n         * 2) other user type that can nest the one we drop and\n         * 3) existing tables referencing the type (maybe in a nested way).\n         */\n        Iterable<UserFunction> functions = keyspace.userFunctions.referencingUserType(name);\n        if (!isEmpty(functions))\n        {\n            throw ire(\"Cannot drop user type '%s.%s' as it is still used by functions %s\",\n                      keyspaceName,\n                      typeName,\n                      join(\", \", transform(functions, f -> f.name().toString())));\n        }\n\n        Iterable<UserType> types = keyspace.types.referencingUserType(name);\n        if (!isEmpty(types))\n        {\n            throw ire(\"Cannot drop user type '%s.%s' as it is still used by user types %s\",\n                      keyspaceName,\n                      typeName,\n                      join(\", \", transform(types, UserType::getNameAsString)));\n\n        }\n\n        Iterable<TableMetadata> tables = keyspace.tables.referencingUserType(name);\n        if (!isEmpty(tables))\n        {\n            throw ire(\"Cannot drop user type '%s.%s' as it is still used by tables %s\",\n                      keyspaceName,\n                      typeName,\n                      join(\", \", transform(tables, t -> t.name)));\n        }\n\n        return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.types.without(type)));\n    }\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/DropTypeStatement.java#L87-L123","documentation":"Reference guard in DropTypeStatement.apply(): the user type being dropped is still nested inside other user types in the same keyspace (detected via keyspace.types referencingUserType). Dropping it would corrupt the dependent type definitions, so the statement is rejected with InvalidRequestException listing the dependent types (this is check 2 of the three reference checks the code documents).","triggerScenarios":"DROP TYPE on a UDT while keyspace.types.referencingUserType(name) is non-empty — other UDTs containing the type as a field (directly or nested).","commonSituations":"Cleaning up old UDTs in schemas with nested types (e.g. address nested in user); dropping inner types of a type hierarchy without dropping dependents first.","solutions":["Drop or alter the dependent user types first so they no longer reference the type; then retry the DROP TYPE; alternatively keep the type if the nested usage is still required."],"exampleFix":"// before\nDROP TYPE ks.address;\n// after\nDROP TYPE ks.user;      -- depends on address\nDROP TYPE ks.address;","handlingStrategy":"validation","validationCode":"var types = session.execute(\"SELECT type_name, field_types FROM system_schema.types WHERE keyspace_name=?\", ks);\n// scan field_types of each UDT for the type being dropped","typeGuard":null,"tryCatchPattern":"try { session.execute(\"DROP TYPE \" + ks + \".\" + type); } catch (InvalidRequest e) { if (e.getMessage().contains(\"still used by user types\")) dropDependentTypesFirst(); else throw e; }","preventionTips":["Map UDT nesting before cleanup (inner types last)","Drop dependent types first, then the referenced type","Avoid reusing UDT names with changed definitions while nested references exist"],"tags":["cassandra","cql","udt","dependency"],"backgroundTag":"schema-validation-failed","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}