dgraph-io / dgraph-docs

A native GraphQL Database with a graph backend
https://dgraph.io/docs
Other
35 stars 66 forks source link

[BUG]: Double wildcard * * not working in delete of an upsert mutation #637

Open faubulous opened 1 year ago

faubulous commented 1 year ago

What version of Dgraph are you using?

v23.0.1

Tell us a little more about your go-environment?

I'm using the dgraph/dgraph:latest image from dockerhub.

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, CPU, OS)?

Fedora 38 Host Intel Core i7 CPU 32GB RAM

What steps will reproduce the bug?

  1. Run this mutation:

    {
    set {
        _:1 <id> "1" .
        _:1 <pred1> _:2 .
        _:2 <pred2> "a" .
        _:2 <pred3> "b" .
    }
    }
  2. Set predicate type to string and enable index, upset and hash on id in the schema.

  3. Run this query to see that pred2 and pred3 exist:

    {
    test(func: has(pred2)) {
        uid
        pred2
        pred3
    }
    }
  4. Run this upsert:

    upsert {
    query {
        q0(func: eq(id, "1")) {
            pred1 {
                id1 as uid
            }
        }
    }
    mutation {
        delete {
            uid(id1) * * .
        }
    }
    }
  5. Run this query again to see that pred2 and pred3 still exist:

    {
    test(func: has(pred2)) {
        uid
        pred2
        pred3
    }
    }
  6. Run this upsert:

    upsert {
    query {
        q0(func: eq(id, "1")) {
            pred1 {
                id1 as uid
            }
        }
    }
    mutation {
        delete {
            uid(id1) <pred2> * .
            uid(id1) <pred3> * .
        }
    }
    }
  7. Run this query again to see that pred2 and pred3 were deleted and the result is empty.

    {
    test(func: has(pred2)) {
        uid
        pred2
        pred3
    }
    }

Expected behavior and actual result.

When executing mutation from step 4 with a wildcard on the predicate, the predicates are not deleted. I would expect mutation from step 4 to have the same outcome as mutation from step 6 that uses explicit predicates as documented here.

Additional information

No response

mangalaman93 commented 1 year ago

uid(id1) * * . is only supposed to work if the UID has a dgraph.type associated with it. See this for more details https://dgraph.io/docs/dql/dql-schema/#when-to-use-node-types

faubulous commented 1 year ago

That explains it. However, it would be great to add or reference this in the documentation about Deleting Data as well: https://dgraph.io/tour/schema/8/

So will the wildcard then only delete the predicates that are defined for the type?

github-actions[bot] commented 1 month ago

This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.