{"record":{"id":"4ec39168eb16ce6f","repo":"dgraph-io/dgraph","slug":"error-while-getting-cors-from-db","errorCode":null,"errorMessage":"Error while getting cors from db.","messagePattern":"Error while getting cors from db\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":377,"sourceCode":"func dropDepreciated(db *badger.DB) error {\n\tvar prefixes [][]byte\n\tfor pred := range deprecatedPreds {\n\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.","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L359-L395","documentation":"fixCors (offline path of OfflineUpgradeFrom2011To2103) reads CORS entries from the restored badger DB with getCors. On failure it wraps the error as 'Error while getting cors from db.' The offline migration could not read dgraph.cors data from the restored backup.","triggerScenarios":"getCors(db) errors while scanning the badger DB for cors data — corrupted restored backup, missing p directory, or badger read failure (IO error, checksum mismatch).","commonSituations":"Restored backup is incomplete or corrupted; wrong directory passed to the offline upgrade; disk/permission issues reading the badger DB; backup from an unexpected Dgraph version.","solutions":["Verify the backup was fully restored into the target post directory and the path passed to the offline upgrade is correct.","Re-restore the backup from source and retry the upgrade.","Check file permissions and disk health on the post directory.","Confirm the backup came from v20.11 and use the matching offline upgrade path."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"ls -la <post-dir>/p && dgraph debug --postings <post-dir>/p  # verify restored badger DB is readable before offline upgrade","typeGuard":null,"tryCatchPattern":"if err := fixCors(db); err != nil {\n\tif strings.Contains(err.Error(), \"Error while getting cors from db.\") {\n\t\t// inspect wrapped cause: re-restore backup or fix path/permissions\n\t}\n\treturn err\n}","preventionTips":["Verify backup restoration completed fully before offline upgrade","Pass the correct post-directory path to the upgrade command","Run the upgrade as a user with read permissions on the badger files","Back up the restored directory before migration"],"tags":["dgraph","upgrade","badger","offline","cors"],"backgroundTag":"badger-db-read-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}