dgraph-io/dgraph · error
Error while updating GraphQL schema.
Error message
Error while updating GraphQL schema.
What it means
This error is a pkg/errors.Wrapf added in fixCors when updateGQLSchemaOffline fails while upgrading a restored 20.11 backup to the 21.03 schema. The offline upgrade rewrites the stored GraphQL schema (including CORS configuration) as badger entries in the p directory; if that write/transform fails, the error is wrapped with this message and propagates up through OfflineUpgradeFrom2011To2103.
Source
Thrown at upgrade/change_v21.03.0.go:380
pred = x.AttrInRootNamespace(pred)
prefixes = append(prefixes, x.SchemaKey(pred), x.PredicatePrefix(pred))
}
for typ := range deprecatedTypes {
prefixes = append(prefixes, x.TypeKey(x.AttrInRootNamespace(typ)))
}
return db.DropPrefix(prefixes...)
}
// fixCors removes the internal predicates from the restored backup. This also appends CORS from
// dgraph.cors to GraphQL schema.
func fixCors(db *badger.DB) error {
glog.Infof("Fixing cors information in the restored backup.")
cors, err := getCors(db)
if err != nil {
return errors.Wrapf(err, "Error while getting cors from db.")
}
if err := updateGQLSchemaOffline(db, cors); err != nil {
return errors.Wrapf(err, "Error while updating GraphQL schema.")
}
return errors.Wrapf(dropDepreciated(db), "Error while dropping depreciated preds/types.")
}
// fixPersistedQuery, for the schema related to persisted query removes the deprecated field from
// the type and updates the index tokenizer for the predicate.
func fixPersistedQuery(db *badger.DB) error {
glog.Infof("Fixing persisted query schema in restored backup.")
update := func(entry *badger.Entry) error {
txn := db.NewTransactionAt(math.MaxUint64, true)
defer txn.Discard()
if err := txn.SetEntry(entry); err != nil {
return err
}
// Schema is written at version 1.
return txn.CommitAt(1, nil)
}
View on GitHub (pinned to 759e242be6)
Solutions
- Inspect the badger p directory for corruption and re-restore the backup from a known-good source, then rerun the upgrade.
- Check the wrapped underlying error (print with %+v) to identify whether the failure was reading getCors-provided schema data or writing entries; fix accordingly (e.g. free disk space, fix permissions).
- Verify the backup version is truly 20.11.x compatible with this offline upgrade path; use the correct dgraph upgrade command for your actual from-version.
- Ensure the dgraph process has write access to the p directory and sufficient disk space before rerunning dgraph upgrade offline.
Example fix
// before (rerun failing upgrade) dgraph upgrade offline -w v21.03.0 // after (re-restore then rerun) dgraph decompress --backup=false -f backup.gz -d ./restore dgraph upgrade offline -w v21.03.0 -d ./restore
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-check before upgrade: verify badger dir opens and schema key exists
db, err := badger.Open(badger.DefaultOptions(pDir))
if err != nil { log.Fatalf("cannot open p dir: %v", err) }
_, err = db.Get([]byte("~graphql.schema")) // presence sanity check
if err != nil && err != badger.ErrKeyNotFound { log.Fatalf("badger read error: %v", err) }
db.Close() Type guard
func isOfflineUpgradeErr(err error) bool {
return err != nil && strings.Contains(err.Error(), "Error while updating GraphQL schema.")
} Try / catch
if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {
log.Fatalf("upgrade failed: %+v", err) // full wrapped chain shows the badger cause
} Prevention
- Always stop all dgraph processes before running the offline upgrade
- Keep a pre-upgrade copy of the p directory for retry
- Ensure ample free disk space before migration
- Log errors with %+v to see the wrapped cause chain
When it happens
Trigger: Running the offline upgrade (OfflineUpgradeFrom2011To2103) on a restored backup whose schema postings are corrupt, unreadable, or malformed so updateGQLSchemaOffline cannot read/rewrite the GraphQL schema entries in badger.
Common situations: Restoring a Dgraph 20.11 backup into a 21.03+ cluster during a version migration; corrupted or partially restored p directory; schema entries written by an older format that the upgrade cannot parse.
Related errors
- Error while dropping depreciated preds/types.
- while updating persisted query's schema
- while updating persisted query's type
- while upgrading persisted query
- while upgrading cors
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/d03784f4d34d2d36.
Report an issue: GitHub.