{"record":{"id":"967afa22a4c6ca8c","repo":"apache/cassandra","slug":"type-s-s-doesn-t-exist","errorCode":null,"errorMessage":"Type %s.%s doesn't exist","messagePattern":"Type (.+?)\\.(.+?) doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java","lineNumber":89,"sourceCode":"    SchemaChange schemaChangeEvent(Keyspaces.KeyspacesDiff diff)\n    {\n        return new SchemaChange(Change.UPDATED, Target.TYPE, keyspaceName, typeName);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n\n        UserType type = null == keyspace\n                      ? null\n                      : keyspace.types.getNullable(bytes(typeName));\n\n        if (null == type)\n        {\n            if (!ifExists)\n                throw ire(\"Type %s.%s doesn't exist\", keyspaceName, typeName);\n            return schema;\n        }\n\n        return schema.withAddedOrUpdated(keyspace.withUpdatedUserType(apply(keyspace, type)));\n    }\n\n    abstract UserType apply(KeyspaceMetadata keyspace, UserType type);\n\n    @Override\n    public AuditLogContext getAuditLogContext()\n    {\n        return new AuditLogContext(AuditLogEntryType.ALTER_TYPE, keyspaceName, typeName);\n    }\n\n    public String toString()\n    {\n        return String.format(\"%s (%s, %s)\", getClass().getSimpleName(), keyspaceName, typeName);\n    }","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/AlterTypeStatement.java#L71-L107","documentation":"Thrown by ALTER TYPE when the user-defined type being altered does not exist in the keyspace. Without `IF EXISTS`, the statement fails rather than silently doing nothing; with `IF EXISTS`, the alteration is a no-op. This guards schema statements against referencing nonexistent type definitions.","triggerScenarios":"Executing `ALTER TYPE ks.typ ADD field type` (or any ALTER TYPE variant) where `keyspace.types.getNullable(bytes(typeName))` returns null, i.e. no UDT of that name exists in the keyspace, and the statement lacks `IF EXISTS`.","commonSituations":"Typo in the type name or keyspace; running a migration before the CREATE TYPE statement; dropping the type in an earlier migration and then trying to alter it; connecting to a cluster where the type was never created.","solutions":["Verify the type exists with `DESCRIBE KEYSPACE ks;` or a system_schema.types query and correct the name","Add `IF EXISTS` (`ALTER TYPE ks.typ ADD ... IF EXISTS`) if a no-op is acceptable when the type is absent","Ensure the migration that creates the type runs before the one that alters it"],"exampleFix":"// before\nALTER TYPE ks.address ADD zip text;\n// after\nALTER TYPE ks.address ADD zip text IF EXISTS;","handlingStrategy":"validation","validationCode":"boolean typeExists = session.execute(\"SELECT type_name FROM system_schema.types WHERE keyspace_name=? AND type_name=?\", ks, typeName).iterator().hasNext();\nif (!typeExists) throw new IllegalStateException(\"Type \" + ks + \".\" + typeName + \" does not exist\");","typeGuard":"boolean userTypeExists(Session s, String ks, String typeName) {\n    return s.execute(\"SELECT type_name FROM system_schema.types WHERE keyspace_name=? AND type_name=?\", ks, typeName).iterator().hasNext();\n}","tryCatchPattern":"try { session.execute(alterTypeStmt); }\ncatch (InvalidQueryException e) {\n    if (e.getMessage().startsWith(\"Type \") && e.getMessage().endsWith(\"doesn't exist\")) {\n        // create the type or skip\n    } else throw e;\n}","preventionTips":["Verify the type in system_schema.types before altering","Use IF EXISTS for optional alterations","Order migrations so CREATE TYPE precedes ALTER TYPE","Fully qualify the keyspace to avoid wrong-keyspace lookups"],"tags":["cql","udt","schema"],"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"}