dgraph-io/dgraph · error
pb.error: all lang tags should be either present or absent
Error message
pb.error: all lang tags should be either present or absent
What it means
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.
Source
Thrown at query/outputnode.go:1562
return err
}
}
}
if len(pc.valueMatrix) <= idx {
continue
}
for i, tv := range pc.valueMatrix[idx].Values {
// if conversion not possible, we ignore it in the result.
sv, convErr := convertWithBestEffort(tv, pc.Attr)
if convErr != nil {
return convErr
}
if pc.Params.ExpandAll && len(pc.LangTags[idx].Lang) != 0 {
if i >= len(pc.LangTags[idx].Lang) {
return errors.Errorf(
"pb.error: all lang tags should be either present or absent")
}
fieldNameWithTag := fieldName
lang := pc.LangTags[idx].Lang[i]
if lang != "" && lang != "*" {
fieldNameWithTag += "@" + lang
}
encodeAsList := pc.List && lang == ""
if err := enc.AddListValue(dst, enc.idForAttr(fieldNameWithTag),
sv, encodeAsList); err != nil {
return err
}
continue
}
encodeAsList := pc.List && len(pc.Params.Langs) == 0
if !pc.Params.Normalize {
err := enc.AddListValue(dst, fieldID, sv, encodeAsList)View on GitHub (pinned to 759e242be6)
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
Example fix
// before (mixed tags)
{
set {
<0x1> <name@en> "Alice" .
<0x1> <name> "Alicia" .
}
}
// after
{
set {
<0x1> <name@en> "Alice" .
<0x1> <name@es> "Alicia" .
}
} Defensive patterns
Strategy: validation
Validate before calling
// before expand(_all_), ensure lang predicates are uniformly tagged
const probe = await dgraph.query('{ q(func: uid($id)) { name@. } }');
// ensure every value has a lang; mixed-tag data triggers the error
if (!probe.q?.[0]) throw new Error('node has untagged values on @lang predicate; re-mutate with tags'); Type guard
function hasLangTag(pred: string): boolean {
return /^\w+@[a-zA-Z*]+$/.test(pred);
} Try / catch
try {
return await dgraph.query(expandAllQuery);
} catch (e) {
if (String(e).includes('lang tags should be either present or absent')) {
return await dgraph.query(projectPredicatesExplicitly); // avoid expand(_all_)
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Schema changed a predicate to @lang after untagged values existed; concurrent mutations adding values with different lang tags; manual bulk mutations bypassing lang validation.
Related errors
- Attr: [%v] should have @lang directive in schema to mutate e
- illegal rune found "%c", expecting {
- JSON map is followed by illegal rune "%c"
- Malformed JSON
- UID must be present and non-zero while deleting edges
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/000a5267090cada3.
Report an issue: GitHub.