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

  1. Re-write all values of the affected predicate with explicit lang tags (pred@en "..."), or delete untagged values
  2. Align the schema: if the predicate should not be language-tagged, remove @lang from the schema and re-mutate
  3. Delete the offending node's values for that predicate and re-mutate consistently
  4. 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

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


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/000a5267090cada3. Report an issue: GitHub.