It works as expected on the first time I clicked run - a new node of type user with all the data is created.
The problem is when I hit run again another node is created even though I have the @upsert directive on User.email and User.username predicates.
according to the documentation:
When committing transactions involving predicates with the @upsert directive, Dgraph checks index keys for conflicts, helping to enforce uniqueness constraints when running concurrent upserts.
Hi @spinelsun
If you start two transactions concurrently and try to commit together, the @upsert directive will come into action and abort one of the transactions. The @upsert directive does not get activated when you commit transactions via Ratel in a back-to-back, non-overlapping fashion.
See @dmai’s note in this ticket: Complete working example of an upsert operation - #2 by dmai
Also, please review this video.
If using an upsert block, is the directive unnecessary? Or should the directive still be placed on the fields to protect against concurrent upsert blocks?
I see this in the docs for upsert block which makes it seem like the directive is unnecessary if using the upsert block, but confirmation would be nice
Upsert operations are intended to be run concurrently, as per the needs of the application. As such, it’s possible that two concurrently running operations could try to add the same node at the same time. For example, both try to add a user with the same email address. If they do, then one of the transactions will fail with an error indicating that the transaction was aborted.
Hi @seanlaff,
Yes, while using the upsert block, @upsert directive is not necessary.
The video shared above does not use an upsert block to demonstrate @upsert directive.