dgraph-io/dgraph · error
Error while getting cors from db.
Error message
Error while getting cors from db.
What it means
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.
Source
Thrown at upgrade/change_v21.03.0.go:377
func dropDepreciated(db *badger.DB) error {
var prefixes [][]byte
for pred := range deprecatedPreds {
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.View on GitHub (pinned to 759e242be6)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
ls -la <post-dir>/p && dgraph debug --postings <post-dir>/p # verify restored badger DB is readable before offline upgrade
Try / catch
if err := fixCors(db); err != nil {
if strings.Contains(err.Error(), "Error while getting cors from db.") {
// inspect wrapped cause: re-restore backup or fix path/permissions
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- error querying cors
- incorrect format for specifying Dgraph.Allow-Origin found fo
- error querying old ACL rules: %w
- unable to parse ACLs: %v
- unable to unmarshal ACL: %v :: %w
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/4ec39168eb16ce6f.
Report an issue: GitHub.