{"record":{"id":"d03784f4d34d2d36","repo":"dgraph-io/dgraph","slug":"error-while-updating-graphql-schema","errorCode":null,"errorMessage":"Error while updating GraphQL schema.","messagePattern":"Error while updating GraphQL schema\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":380,"sourceCode":"\t\tpred = x.AttrInRootNamespace(pred)\n\t\tprefixes = append(prefixes, x.SchemaKey(pred), x.PredicatePrefix(pred))\n\t}\n\tfor typ := range deprecatedTypes {\n\t\tprefixes = append(prefixes, x.TypeKey(x.AttrInRootNamespace(typ)))\n\t}\n\treturn db.DropPrefix(prefixes...)\n}\n\n// fixCors removes the internal predicates from the restored backup. This also appends CORS from\n// dgraph.cors to GraphQL schema.\nfunc fixCors(db *badger.DB) error {\n\tglog.Infof(\"Fixing cors information in the restored backup.\")\n\tcors, err := getCors(db)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"Error while getting cors from db.\")\n\t}\n\tif err := updateGQLSchemaOffline(db, cors); err != nil {\n\t\treturn errors.Wrapf(err, \"Error while updating GraphQL schema.\")\n\t}\n\treturn errors.Wrapf(dropDepreciated(db), \"Error while dropping depreciated preds/types.\")\n}\n\n// fixPersistedQuery, for the schema related to persisted query removes the deprecated field from\n// the type and updates the index tokenizer for the predicate.\nfunc fixPersistedQuery(db *badger.DB) error {\n\tglog.Infof(\"Fixing persisted query schema in restored backup.\")\n\tupdate := func(entry *badger.Entry) error {\n\t\ttxn := db.NewTransactionAt(math.MaxUint64, true)\n\t\tdefer txn.Discard()\n\t\tif err := txn.SetEntry(entry); err != nil {\n\t\t\treturn err\n\t\t}\n\t\t// Schema is written at version 1.\n\t\treturn txn.CommitAt(1, nil)\n\t}\n","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L362-L398","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (rerun failing upgrade)\ndgraph upgrade offline -w v21.03.0\n// after (re-restore then rerun)\ndgraph decompress --backup=false -f backup.gz -d ./restore\ndgraph upgrade offline -w v21.03.0 -d ./restore","handlingStrategy":"try-catch","validationCode":"// Pre-check before upgrade: verify badger dir opens and schema key exists\ndb, err := badger.Open(badger.DefaultOptions(pDir))\nif err != nil { log.Fatalf(\"cannot open p dir: %v\", err) }\n_, err = db.Get([]byte(\"~graphql.schema\")) // presence sanity check\nif err != nil && err != badger.ErrKeyNotFound { log.Fatalf(\"badger read error: %v\", err) }\ndb.Close()","typeGuard":"func isOfflineUpgradeErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"Error while updating GraphQL schema.\")\n}","tryCatchPattern":"if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {\n\tlog.Fatalf(\"upgrade failed: %+v\", err) // full wrapped chain shows the badger cause\n}","preventionTips":["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"],"tags":["badger","migration","schema","offline-upgrade"],"backgroundTag":"offline-schema-upgrade-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}