{"record":{"id":"ae3a5da898a5bbe5","repo":"apache/cassandra","slug":"cannot-drop-user-type-s-s-as-it-is-still-used","errorCode":null,"errorMessage":"Cannot drop user type '%s.%s' as it is still used by functions %s","messagePattern":"Cannot drop user type '(.+?)\\.(.+?)' as it is still used by functions (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/DropTypeStatement.java","lineNumber":96,"sourceCode":"            if (ifExists)\n                return schema;\n\n            throw ire(\"Type '%s.%s' doesn't exist\", keyspaceName, typeName);\n        }\n\n        /*\n         * We don't want to drop a type unless it's not used anymore (mainly because\n         * if someone drops a type and recreates one with the same name but different\n         * 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        {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/DropTypeStatement.java#L78-L114","documentation":"The user-defined type is still referenced by one or more user functions, so Cassandra refuses to drop it. Dropping a UDT that functions depend on would leave the function signatures broken, so the dependency check blocks the drop and names the offending functions.","triggerScenarios":"DROP TYPE on a UDT while keyspace.userFunctions.referencingUserType(name) is non-empty — i.e. functions whose signatures (params/return type) use the type.","commonSituations":"Schemas where UDFs were created using UDTs and later attempts to clean up the types; refactoring types without auditing function dependencies.","solutions":["Drop or ALTER the listed functions so they no longer reference the type, then reissue DROP TYPE","Use system_schema.functions to find functions referencing the type","If the type definition only needs to change, ALTER TYPE instead of drop/recreate"],"exampleFix":"// before\nDROP TYPE ks.geo;\n// after\nDROP FUNCTION ks.dist(geo);\nDROP TYPE ks.geo;","handlingStrategy":"validation","validationCode":"var funcs = session.execute(\"SELECT function_name FROM system_schema.functions WHERE keyspace_name=?\", ks);\n// also inspect argument_types and return_type for the UDT name before dropping","typeGuard":null,"tryCatchPattern":"try { session.execute(\"DROP TYPE \" + ks + \".\" + type); } catch (InvalidRequest e) { if (e.getMessage().contains(\"still used by functions\")) dropFunctionsFirst(); else throw e; }","preventionTips":["Audit function signatures (argument_types, return_type) for UDT usage before dropping types","Prefer ALTER TYPE over drop/recreate when only the definition changes","Drop dependents in order: functions -> types -> tables"],"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"}