{"record":{"id":"87dbeb9b0d5ec291","repo":"dgraph-io/dgraph","slug":"subject-and-object-both-should-be-got-v","errorCode":null,"errorMessage":"Subject and object both should be *. Got: %+v","messagePattern":"Subject and object both should be \\*\\. Got: %\\+v","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dql/mutation.go","lineNumber":148,"sourceCode":"}\n\n// CreateValueEdge returns a DirectedEdge with the given subject. The predicate,\n// language, and facet values are derived from the NQuad.\nfunc (nq NQuad) CreateValueEdge(subjectUid uint64) (*pb.DirectedEdge, error) {\n\tvar err error\n\n\tout := nq.createEdgePrototype(subjectUid)\n\tif err = copyValue(out, nq); err != nil {\n\t\treturn &emptyEdge, err\n\t}\n\treturn out, nil\n}\n\n// ToDeletePredEdge takes an NQuad of the form '* p *' and returns the equivalent\n// directed edge. Returns an error if the NQuad does not have the expected form.\nfunc (nq NQuad) ToDeletePredEdge() (*pb.DirectedEdge, error) {\n\tif nq.Subject != x.Star && nq.ObjectValue.String() != x.Star {\n\t\treturn &emptyEdge, errors.Errorf(\"Subject and object both should be *. Got: %+v\", nq)\n\t}\n\n\tout := &pb.DirectedEdge{\n\t\t// This along with edge.ObjectValue == x.Star would indicate\n\t\t// that we want to delete the predicate.\n\t\tEntity:    0,\n\t\tAttr:      nq.Predicate,\n\t\tNamespace: nq.Namespace,\n\t\tLang:      nq.Lang,\n\t\tFacets:    nq.Facets,\n\t\tOp:        pb.DirectedEdge_DEL,\n\t}\n\n\tif err := copyValue(out, nq); err != nil {\n\t\treturn &emptyEdge, err\n\t}\n\treturn out, nil\n}","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dql/mutation.go#L130-L166","documentation":"ToDeletePredEdge converts an NQuad of the canonical form `* predicate *` into a directed edge that drops the entire predicate. This error is thrown when the NQuad does not have BOTH subject and object equal to `*`, i.e. it is not a valid predicate-deletion directive (`Subject and object both should be *`). The library enforces this so partial-value deletions are not mistaken for dropping a whole predicate via alter.","triggerScenarios":"Calling NQuad.ToDeletePredEdge (directly or via an alter/drop-attribute flow) with an NQuad whose Subject is not `x.Star` or whose ObjectValue is not `x.Star`, e.g. `<0x1> <age> *` or `* <age> \"42\"`.","commonSituations":"Building drop-predicate requests programmatically and populating subject/object with actual node ids or values instead of the literal `*`, or reusing a normal set/delete NQuad in a drop-all-attribute API call.","solutions":["Construct the NQuad with Subject = \"*\" and ObjectValue = \"*\" before calling ToDeletePredEdge.","If you intend to delete one node's value, use a normal delete mutation (`<0x1> <age> * .`) instead of ToDeletePredEdge/alter.","Check upstream code that copies fields into the NQuad and ensure it does not overwrite subject/object with concrete values.","Validate the raw RDF line: only `* <pred> * .` is valid for predicate deletion."],"exampleFix":"// before\nnq := NQuad{Subject: \"0x1\", Predicate: \"age\", ObjectValue: star} // invalid\n// after\nnq := NQuad{Subject: x.Star, Predicate: \"age\", ObjectValue: &api.Value{Str: x.Star}}\nedge, err := nq.ToDeletePredEdge()","handlingStrategy":"validation","validationCode":"func isPredDeleteNQuad(nq NQuad) bool {\n    return nq.Subject == \"*\" && nq.ObjectValue != nil && nq.ObjectValue.String() == \"*\"\n}","typeGuard":"func (nq NQuad) IsStarAll() bool {\n    return nq.Subject == \"*\" && nq.ObjectValue.String() == \"*\"\n}","tryCatchPattern":"edge, err := nq.ToDeletePredEdge()\nif err != nil {\n    if strings.Contains(err.Error(), \"Subject and object both should be *\") {\n        return fmt.Errorf(\"predicate deletion requires exactly '* <pred> *': %w\", err)\n    }\n    return err\n}","preventionTips":["Only call ToDeletePredEdge on NQuads of the literal form `* <pred> *`.","Use regular delete mutations for per-node value deletions, not alter/drop.","Sanitize NQuads built from user RDF lines before routing them to alter."],"tags":["dgraph","mutation","alter"],"backgroundTag":"invalid-star-delete-nquad","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}