Upsert On Facet?

Hi there,
Is it possible to create an @upsert directive on a facet key?

I am using DQL and I have a many-to-many relationship between say Users and Cars. A user can have many cars and a car can be owned by many users.

More importantly, there’s an edge attribute (facet) between a user and a car called “token”.

An anonymous user presenting a token should retrieve exactly one car that belongs to that user.

Therefore, I must ensure that a token can never be created twice. We don’t want to give the wrong car to the wrong user.

However, when running a concurrent transaction that creates a new car and adds a token to it, trying to upsert on the token facet does not abort the transaction.

Is it possible to upsert on a facet so that we make sure to never create the same facet value twice?

Here’s what I’m doing:

  1. Create a new transaction
  2. Look up a car by token to see if it already exists
  3. If the token exists, error out, otherwise create the car.
  4. Commit the transaction, check if the transaction is aborted to guard against concurrent requests.

Currently, if I run the 4 steps above in parallel a few times, none of the transactions are aborted and I end up with duplicate tokens.

Happy to provide queries and reproduction as well.

Thanks!