Skip to content

Commit

Permalink
fix(query): Prevent multiple entries for same predicate/type in schem…
Browse files Browse the repository at this point in the history
…a mutations. (#7715)

* fix(query): Prevent multiple entries for the same predicate/type in mutations.

Fixes DGRAPH-3225
  • Loading branch information
rohanprasad authored and dshekhar95 committed Sep 15, 2022
1 parent 52f1365 commit a6cec60
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions edgraph/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,15 @@ func parseSchemaFromAlterOperation(ctx context.Context, op *api.Operation) (*sch
return nil, err
}

preds := make(map[string]struct{})

for _, update := range result.Preds {
if _, ok := preds[update.Predicate]; ok {
return nil, errors.Errorf("predicate %s defined multiple times",
x.ParseAttr(update.Predicate))
}
preds[update.Predicate] = struct{}{}

// Pre-defined predicates cannot be altered but let the update go through
// if the update is equal to the existing one.
if schema.IsPreDefPredChanged(update) {
Expand All @@ -310,7 +318,14 @@ func parseSchemaFromAlterOperation(ctx context.Context, op *api.Operation) (*sch
}
}

types := make(map[string]struct{})

for _, typ := range result.Types {
if _, ok := types[typ.TypeName]; ok {
return nil, errors.Errorf("type %s defined multiple times", x.ParseAttr(typ.TypeName))
}
types[typ.TypeName] = struct{}{}

// Pre-defined types cannot be altered but let the update go through
// if the update is equal to the existing one.
if schema.IsPreDefTypeChanged(typ) {
Expand Down

0 comments on commit a6cec60

Please sign in to comment.