MySQL - How can a deadlock b caused by the same transaction?
I suggest you add code to make the product more robust.  Check for deadlocks after every statement.  When you encounter such, replay the statement(s) in the transaction.

That may be cheaper than figuring out all the possible causes of deadlocks (you have shown one, but there could be more).  Later you can worry about the extra unique key.  But leave the checks for deadlocks in place even if they never happen again.

Adding to FOR UPDATE to the SELECT.