Skip to content

Commit 91fcf6a

Browse files
authored
Fix bug in exporting types with reverse predicates. (#4857)
< > brackets are needed around the type name. They were missing.
1 parent 9bed827 commit 91fcf6a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

worker/export.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,15 @@ func toType(attr string, update pb.TypeUpdate) (*bpb.KVList, error) {
333333
func fieldToString(update *pb.SchemaUpdate) string {
334334
var builder strings.Builder
335335
x.Check2(builder.WriteString("\t"))
336-
x.Check2(builder.WriteString(update.Predicate))
336+
// While exporting type definitions, "<" and ">" brackets must be written around
337+
// the name of everse predicates or Dgraph won't be able to parse the exported schema.
338+
if strings.HasPrefix(update.Predicate, "~") {
339+
x.Check2(builder.WriteString("<"))
340+
x.Check2(builder.WriteString(update.Predicate))
341+
x.Check2(builder.WriteString(">"))
342+
} else {
343+
x.Check2(builder.WriteString(update.Predicate))
344+
}
337345
x.Check2(builder.WriteString("\n"))
338346
return builder.String()
339347
}

worker/export_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ var personType = &pb.TypeUpdate{
5757
{
5858
Predicate: "friend",
5959
},
60+
{
61+
Predicate: "~friend",
62+
},
6063
{
6164
Predicate: "friend_not_served",
6265
},

0 commit comments

Comments
 (0)