I want to update only one node returned in the query block of the upsert while using @cascade, but the request mutates (sets or deletes) all matching nodes instead.
What I did
This happens 100% of the time, but only with @cascade.
I’m using @cascade to exclude nodes that don’t have all of the predicates I’m querying and with predicates that contain specific values (doing some @filter(uid_in(pred, uid(abc))) stuff), ultimately finding the first matching node and then applying a mutation in the same request.
By the way, I just found a workaround:
upsert {
query {
q(func: has(a), first: 1) @normalize @cascade {
tmp as uid
a
}
x as var(func: uid(tmp), first: 1)
}
mutation {
set {
uid(x) <a> "Changed value" .
}
}
}
I use @normalize because I also read the predicates returned by the request and need (well want) them in a particular format, the same format that I use for regular ol’ read requests.
Sorry, didn’t see this reply until now. Sure, in this specific case I didn’t need a result from it, but I do in my real use case, in a much larger query with more information than I thought would be useful to show the bug.
I don’t think I’ve solved the issue. I’m not sure what I did is 100% correct but I am pretty sure the originally reported behavior is incorrect – that is, deleting and updating data other than that which was intended (kind of frightening, in fact). If it is the intended, correct behavior I think it’d be worth putting a warning about it in the @cascade documentation (font size 72pt+).
FWIW: I just noticed a bug in the cleanup query I pasted in the initial post: