{"record":{"id":"000a5267090cada3","repo":"dgraph-io/dgraph","slug":"pb-error-all-lang-tags-should-be-either-present-o","errorCode":null,"errorMessage":"pb.error: all lang tags should be either present or absent","messagePattern":"pb\\.error: all lang tags should be either present or absent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/outputnode.go","lineNumber":1562,"sourceCode":"\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif len(pc.valueMatrix) <= idx {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tfor i, tv := range pc.valueMatrix[idx].Values {\n\t\t\t\t// if conversion not possible, we ignore it in the result.\n\t\t\t\tsv, convErr := convertWithBestEffort(tv, pc.Attr)\n\t\t\t\tif convErr != nil {\n\t\t\t\t\treturn convErr\n\t\t\t\t}\n\n\t\t\t\tif pc.Params.ExpandAll && len(pc.LangTags[idx].Lang) != 0 {\n\t\t\t\t\tif i >= len(pc.LangTags[idx].Lang) {\n\t\t\t\t\t\treturn errors.Errorf(\n\t\t\t\t\t\t\t\"pb.error: all lang tags should be either present or absent\")\n\t\t\t\t\t}\n\t\t\t\t\tfieldNameWithTag := fieldName\n\t\t\t\t\tlang := pc.LangTags[idx].Lang[i]\n\t\t\t\t\tif lang != \"\" && lang != \"*\" {\n\t\t\t\t\t\tfieldNameWithTag += \"@\" + lang\n\t\t\t\t\t}\n\t\t\t\t\tencodeAsList := pc.List && lang == \"\"\n\t\t\t\t\tif err := enc.AddListValue(dst, enc.idForAttr(fieldNameWithTag),\n\t\t\t\t\t\tsv, encodeAsList); err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tencodeAsList := pc.List && len(pc.Params.Langs) == 0\n\t\t\t\tif !pc.Params.Normalize {\n\t\t\t\t\terr := enc.AddListValue(dst, fieldID, sv, encodeAsList)","sourceCodeStart":1544,"sourceCodeEnd":1580,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/outputnode.go#L1544-L1580","documentation":"When expanding all predicates (ExpandAll) with language-tagged predicates, Dgraph expects the per-value loop counter i to have a matching entry in LangTags[idx].Lang. A value with more occurrences than registered language tags means internal language metadata is inconsistent, so it errors rather than emitting a field with an unknown tag.","triggerScenarios":"An expand(_all_) (or ExpandAll) query over a node with @lang predicates where pc.LangTags[idx].Lang has fewer entries than the value index i — typically after mixed write patterns: some values written with @lang tags, others without, or corrupted lang metadata.","commonSituations":"Schema changed a predicate to @lang after untagged values existed; concurrent mutations adding values with different lang tags; manual bulk mutations bypassing lang validation.","solutions":["Re-write all values of the affected predicate with explicit lang tags (pred@en \"...\"), or delete untagged values","Align the schema: if the predicate should not be language-tagged, remove @lang from the schema and re-mutate","Delete the offending node's values for that predicate and re-mutate consistently","Upgrade Dgraph if the mismatch occurs with consistent data — check LangTags population bug"],"exampleFix":"// before (mixed tags)\n{\n  set {\n    <0x1> <name@en> \"Alice\" .\n    <0x1> <name> \"Alicia\" .\n  }\n}\n// after\n{\n  set {\n    <0x1> <name@en> \"Alice\" .\n    <0x1> <name@es> \"Alicia\" .\n  }\n}","handlingStrategy":"validation","validationCode":"// before expand(_all_), ensure lang predicates are uniformly tagged\nconst probe = await dgraph.query('{ q(func: uid($id)) { name@. } }');\n// ensure every value has a lang; mixed-tag data triggers the error\nif (!probe.q?.[0]) throw new Error('node has untagged values on @lang predicate; re-mutate with tags');","typeGuard":"function hasLangTag(pred: string): boolean {\n  return /^\\w+@[a-zA-Z*]+$/.test(pred);\n}","tryCatchPattern":"try {\n  return await dgraph.query(expandAllQuery);\n} catch (e) {\n  if (String(e).includes('lang tags should be either present or absent')) {\n    return await dgraph.query(projectPredicatesExplicitly); // avoid expand(_all_)\n  }\n  throw e;\n}","preventionTips":["Always write values with explicit @lang tags once a predicate is @lang in schema","Avoid changing a predicate to @lang while untagged values exist; migrate first","Use explicit predicate projection instead of expand(_all_) over lang-heavy nodes","Scan for untagged values after schema language migrations"],"tags":["dgraph","i18n","lang-tags","expand"],"backgroundTag":"lang-tag-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}