selmeci / dgraph-tonic

Async/Sync gRPC client for Dgraph DB
MIT License
83 stars 8 forks source link

upsert fails in dgraph 24.02 #40

Closed escquery closed 1 day ago

escquery commented 6 days ago

The code below runs fine in dgraph 23.10:

  let mut mu = Mutation::new();
  mu.set_cond(format!("@if(eq(len(system), 0) AND eq(len(envs), 2))"));
  mu.set_set_nquads(format!(
      r#"_:system <system_id> "test" .
_:system <system_name> "{name}" .
_:system <dgraph.type> "System" .
uid(envs) <env_systems> _:system ."#
  ));
  let q = r#"{system as var(func: eq(system_id, "test"))
envs as var(func: eq(env_id, ["uat","dev"]))
system(func: uid(system)) { uid }
env(func: uid(envs)) { count(uid) }}"#
  txn.upsert_and_commit_now(q, mu).await

After I upgraded to 24.02 and added unique indexes for system_id and env_id, I got the error:

Caused by:
    Client: cannot do request.
    Status { code: Unknown, message: "while lexing {system as var(func: eq(system_id, \"test\"))\n  envs as var(func: eq(env_id, [\"uat\",\"dev\"]))\n  system(func: uid(system)) { uid }\n  env(func: uid(envs)) { count(uid) __dgraph_uniquecheck_0__ as var(func: eq(system_id,\"test\"))__dgraph_upsertcheck_0__ as var(func: uid(0)) @filter(eq(len(system), 0) AND eq(len(envs), 2))\n} at line 5 column 1: Unclosed action", metadata: MetadataMap { headers: {"content-type": "application/grpc", "content-length": "0", "date": "Wed, 27 Nov 2024 03:03:55 GMT"} }, source: None }

dependencies:

dgraph-tonic = { version = "0.11", features = ["dgraph-21-03"], default-features = false }
escquery commented 1 day ago

I just changed q to look like below and it was fine:

  let q = r#"{system as var(func: eq(system_id, "test"))
envs as var(func: eq(env_id, ["uat","dev"]))
system(func: uid(system)) { uid }
env(func: uid(envs)) { count(uid) }
}"#