Upsert not working

In my case, I need to mutate list of classes which have a foreign key teacher_id. While “upsert” feature is not working for teacher_id.

And then I read the uid of teacher before inserting and committing each class, but uid returns None. I guess it is because Dgraph commits the transactions in a batch, although I set the commit by each class. After committing all the jobs, I query the teachers, which returns multiple teacher nodes for the same id.

Am I using the “upsert” right? Would you help me how to handle this case? Thanks.

BTW, I am using Dgraph Docker v1.0.7, and pydgraph==1.0.0

Schema:
teacher_id: string @index(hash, trigram) @upsert .

You need to share a close to real usage code example.
However, I’m not a Python developer, but I can try to help. And anyone else who develops with py and is available is welcome.

One note, we did not use “foreign key”. Are you talking about external ID?

The upsert’s structure is more or less like this:

open Txn > Query for a value with @upsert
        |> if true returns an UID and discart || else return false and continue
        |> RUN a mutation to create one e.g. "account"
        |> Commit
        |> discart
> All Done in one transaction.

Cheers.