Fixed User upgrade duplicate key exception

Affected version
2.0 Beta 7


Well-known member
XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry '14' for key 'PRIMARY' src/XF/Db/AbstractStatement.php:212

Generated by: Snog Oct 20, 2017 at 8:57 AM

Stack trace

UPDATE  xf_user_upgrade_active SET `user_upgrade_record_id` = ? WHERE `user_upgrade_record_id` = 11

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1062, '23000')
#1 src/XF/Db/Mysqli/Statement.php(69): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1062, '23000')
#2 src/XF/Db/AbstractAdapter.php(69): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(228): XF\Db\AbstractAdapter->query('UPDATE  xf_user...', Array)
#4 src/XF/Mvc/Entity/Entity.php(1179): XF\Db\AbstractAdapter->update('xf_user_upgrade...', Array, '`user_upgrade_r...')
#5 src/XF/Service/User/Upgrade.php(186): XF\Mvc\Entity\Entity->fastUpdate('user_upgrade_re...', 14)
#6 src/XF/Admin/Controller/UserUpgrade.php(167): XF\Service\User\Upgrade->upgrade()
#7 src/XF/Mvc/Dispatcher.php(249): XF\Admin\Controller\UserUpgrade->actionManual(Object(XF\Mvc\ParameterBag))
#8 src/XF/Mvc/Dispatcher.php(87): XF\Mvc\Dispatcher->dispatchClass('XF:UserUpgrade', 'Manual', 'json', Object(XF\Mvc\ParameterBag), 'userUpgrades', Object(XF\Admin\Controller\UserUpgrade), NULL)
#9 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#10 src/XF/App.php(1844): XF\Mvc\Dispatcher->run()
#11 src/XF.php(328): XF\App->run()
#12 admin.php(13): XF::runApp('XF\\Admin\\App')
#13 {main}

Request state

array(4) {
  ["url"] => string(38) "/admin.php?user-upgrades/test.1/manual"
  ["referrer"] => string(58) ""
  ["_GET"] => array(1) {
    ["user-upgrades/test_1/manual"] => string(0) ""
  ["_POST"] => array(7) {
    ["username"] => string(5) "Joe"
    ["end_type"] => string(4) "date"
    ["end_date"] => string(10) "2017-12-29"
    ["_xfToken"] => string(8) "********"
    ["_xfRequestUri"] => string(38) "/admin.php?user-upgrades/test.1/manual"
    ["_xfWithData"] => string(1) "1"
    ["_xfResponseType"] => string(4) "json"
Record ID14 is for a different user. Joe is user ID 2 and I would expect it to use record ID 11.

This one is tough to duplicate, but I can usually duplicate it by taking these steps...

1) Manually upgrade a user with an end date of 'Permanent'
2) Manually upgrade another user with an end date set to "Permanent" for the same user upgrade used in step 1
3) Try to manually upgrade the same user used in step 1 with the same user upgrade, but this time set an arbitrary end date.

I would expect the user's end date to be updated (record 11) when this is done. And I don't know where record 14 is coming into play.

The bad thing is, this doesn't happen all of the time.
Last edited:


XenForo developer
Staff member
This is fixed for the next release. This code should have only applied when an active upgrade was first inserted. It looks like it was running on updates too.