{"record":{"id":"d526a01688f2db47","repo":"apache/cassandra","slug":"unknown-field-s-in-value-of-user-defined-type","errorCode":null,"errorMessage":"Unknown field '%s' in value of user defined type %s","messagePattern":"Unknown field '(.+?)' in value of user defined type (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/terms/UserTypes.java","lineNumber":168,"sourceCode":"                Term.Raw raw = entries.get(field);\n                if (raw == null)\n                    raw = Constants.NULL_LITERAL;\n                else\n                    ++foundValues;\n                Term value = raw.prepare(keyspace, fieldSpecOf(receiver, i));\n\n                if (value instanceof Term.NonTerminal)\n                    allTerminal = false;\n\n                values.add(value);\n            }\n            if (foundValues != entries.size())\n            {\n                // We had some field that are not part of the type\n                for (FieldIdentifier id : entries.keySet())\n                {\n                    if (!ut.fieldNames().contains(id))\n                        throw new InvalidRequestException(String.format(\"Unknown field '%s' in value of user defined type %s\", id, ut.getNameAsString()));\n                }\n            }\n\n            MultiElements.DelayedValue value = new MultiElements.DelayedValue(((UserType)receiver.type.unwrap()), values);\n            return allTerminal ? value.bind(FunctionContext.NONE) : value;\n        }\n\n        private void validateAssignableTo(String keyspace, ColumnSpecification receiver) throws InvalidRequestException\n        {\n            AbstractType<?> unwrapped = receiver.type.unwrap();\n\n            if (!unwrapped.isUDT())\n                throw new InvalidRequestException(String.format(\"Invalid user type literal for %s of type %s\", receiver.name, receiver.type.asCQL3Type()));\n\n            UserType ut = (UserType)unwrapped;\n            for (int i = 0; i < ut.size(); i++)\n            {\n                FieldIdentifier field = ut.fieldName(i);","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/terms/UserTypes.java#L150-L186","documentation":"Cassandra throws this InvalidRequestException when a user type (UDT) literal in CQL contains a field name that does not exist in the target user type definition. The literal binder (UserTypes.Literal.prepare) checks every field given in the `{field: value, ...}` literal against the UserType's declared field names and rejects unknown ones.","triggerScenarios":"Executing a statement with a UDT literal like `{street: 'a', city: 'b'}` bound to a UDT column where a field name (e.g. `street`) is not among the type's fields, e.g. after schema drift, a typo, or the literal was parsed before the type was checked.","commonSituations":"Typos in field names in INSERT/UPDATE literals; UDT definition changed (field renamed/removed) between statement construction and execution; reusing query templates across keyspaces with different UDT definitions.","solutions":["Correct the field names in the UDT literal to match the type definition (DESCRIBE TYPE / system_schema.types).","Verify the keyspace and UDT name in the statement refer to the intended type version.","Rebuild prepared statements after altering the UDT so field names are revalidated.","Use ALLOW... no — instead generate literals from the actual type metadata rather than hardcoding fields."],"exampleFix":"// before\nINSERT INTO ks.t (id, addr) VALUES (1, {street: 'Main', city: 'X'}); // addr has field 'st_address', not 'street'\n// after\nINSERT INTO ks.t (id, addr) VALUES (1, {st_address: 'Main', city: 'X'});","handlingStrategy":"validation","validationCode":"Set<String> valid = userType.getFieldNames();\nfor (String f : literalFields) if (!valid.contains(f)) throw new IllegalArgumentException(\"Unknown UDT field: \" + f);","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Unknown field\")) fixLiteralFields(); else throw e; }","preventionTips":["Generate UDT literals from type metadata, not hardcoded field names","Re-prepare statements after ALTER TYPE","DESCRIBE the UDT before writing literals"],"tags":["cql","udt","invalid-request"],"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"}