{"record":{"id":"aa55aea70b6cc5d2","repo":"dgraph-io/dgraph","slug":"attr-v-should-have-lang-directive-in-schema-t","errorCode":null,"errorMessage":"Attr: [%v] should have @lang directive in schema to mutate edge: [%v]","messagePattern":"Attr: \\[(.+?)\\] should have @lang directive in schema to mutate edge: \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"worker/mutation.go","lineNumber":526,"sourceCode":"\n\tif isDeletePredicateEdge(edge) {\n\t\treturn nil\n\t}\n\tif types.TypeID(edge.ValueType) == types.DefaultID && isStarAll(edge.Value) {\n\t\treturn nil\n\t}\n\n\tif strings.Contains(su.Predicate, hnsw.VecKeyword) {\n\t\treturn errors.Errorf(\"Not allowed to insert mutations in vector index keys, edge: [%v]\", edge)\n\t}\n\n\tstorageType := posting.TypeID(edge)\n\tschemaType := types.TypeID(su.ValueType)\n\n\t// type checks\n\tswitch {\n\tcase edge.Lang != \"\" && !su.GetLang():\n\t\treturn errors.Errorf(\"Attr: [%v] should have @lang directive in schema to mutate edge: [%v]\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase !schemaType.IsScalar() && !storageType.IsScalar():\n\t\treturn nil\n\n\tcase !schemaType.IsScalar() && storageType.IsScalar():\n\t\treturn errors.Errorf(\"Input for predicate %q of type uid is scalar. Edge: %v\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase schemaType.IsScalar() && !storageType.IsScalar():\n\t\treturn errors.Errorf(\"Input for predicate %q of type scalar is uid. Edge: %v\",\n\t\t\tx.ParseAttr(edge.Attr), edge)\n\n\tcase schemaType == types.TypeID(pb.Posting_VFLOAT):\n\t\tif !(storageType == types.TypeID(pb.Posting_VFLOAT) || storageType == types.TypeID(pb.Posting_STRING) ||\n\t\t\tstorageType == types.TypeID(pb.Posting_DEFAULT)) {\n\t\t\treturn errors.Errorf(\"Input for predicate %q of type vector is not vector.\"+\n\t\t\t\t\" Did you forget to add quotes before []?. Edge: %v\", x.ParseAttr(edge.Attr), edge)","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/mutation.go#L508-L544","documentation":"If a mutation edge carries a language tag (@lang value on the edge) but the predicate's schema was not declared with the @lang directive, ValidateAndConvert rejects the mutation: Dgraph will not store language-tagged values for a predicate not marked @lang.","triggerScenarios":"Sending a mutation with a language-tagged edge (e.g. RDF with @en, or edge.Lang set in the DirectedEdge) for a predicate whose SchemaUpdate lacks the Lang flag, i.e. schema is `name string @index(term) .` without @lang.","commonSituations":"Localizing an app by adding @en/@fr/@de values before updating the schema; GraphQL or client drivers that set language tags automatically; schema altered in one environment but not another.","solutions":["Alter the schema to add @lang: `name string @index(term) @lang .` then retry the mutation.","Remove the language tag from the mutation value if a single untagged value is intended.","Check the current schema (query schema(pred: [\"name\"])) to confirm whether @lang is set."],"exampleFix":"// schema before (fails)\nname string @index(term) .\n// mutation\n<0x1> <name> \"Hello\"@en .\n\n// schema after\nname string @index(term) @lang .","handlingStrategy":"validation","validationCode":"async function assertLangDirective(dgraph, pred) {\n  const schema = await dgraph.newTxn().query(`schema(pred: [\"${pred}\"])`)\n  const p = schema.data.schema[0]\n  if (!p.lang) throw new Error(`${pred} lacks @lang; cannot write language-tagged values`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await txn.mutate(mu)\n} catch (e) {\n  if (String(e).includes('should have @lang directive')) {\n    // alter schema to add @lang, then retry the mutation\n  }\n}","preventionTips":["Add @lang to any predicate you plan to localize before shipping i18n mutations.","Keep schema in sync across dev/staging/prod environments.","Strip language tags for single-language fields instead of relying on @lang everywhere."],"tags":["dgraph","mutation","i18n","schema"],"backgroundTag":"missing-lang-directive","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}