An app logs Deadlock found when trying to get lock and retries, but the error says nothing about the other side. InnoDB keeps a report of the most recent one.
mariadb -e 'SHOW ENGINE INNODB STATUS\G' | grep -A 40 'LATEST DETECTED DEADLOCK'
The section lists transaction (1) and transaction (2), the statement each one was running, the locks it held and the lock it waited for. At the end it says which one InnoDB rolled back. I’d make a deadlock on purpose with two sessions that update the same two rows in opposite order, and the report shows both UPDATE statements and the index they fight over.
The usual fix is boring: touch rows in the same order in every code path, and keep transactions short.
Two limits. The section only appears after a deadlock has happened since the server started, and it only holds the latest one, so a second deadlock overwrites the first. If they happen often, turn on logging of all of them:
SET GLOBAL innodb_print_all_deadlocks = ON;
Then each one goes to the error log. That setting is lost on restart unless you put it in the server config. The status output needs the PROCESS privilege, so an app user usually cannot run it.
Further reading: SHOW ENGINE INNODB STATUS, InnoDB system variables