joomla/joomla-cms — pull request #4861 by aDaneInSpain (2014-10-20 12:09:14+00:00)
Title: This should fix #4836 but is not tested

I have not been able to test this (as the issue occurs intermittently), but this should fix the issue. I guess the true and correct way of fixing this would be to find out why this occurs in the first place, but the "ON DUPLICATE KEY UPDATE" should fix the issue regardless.