From 6d89076e3a88c4a147bb3be0a54c57d802706ef5 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 19 Jun 2013 14:13:19 -0700 Subject: [PATCH] Avoid the "key conflict attempting to insert a user row" exception in some cases bug: 41609 Change-Id: Iebfcf50e648a43f2970e6d0e4073cb6d84d260df --- includes/User.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/User.php b/includes/User.php index 1c13211cd7..b6d2377c7c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -3272,6 +3272,7 @@ class User { $this->mTouched = self::newTouchedTimestamp(); $dbw = wfGetDB( DB_MASTER ); + $inWrite = $dbw->writesOrCallbacksPending(); $seqVal = $dbw->nextSequenceValue( 'user_user_id_seq' ); $dbw->insert( 'user', array( @@ -3291,6 +3292,12 @@ class User { array( 'IGNORE' ) ); if ( !$dbw->affectedRows() ) { + if ( !$inWrite ) { + // XXX: Get out of REPEATABLE-READ so the SELECT below works. + // Often this case happens early in views before any writes. + // This shows up at least with CentralAuth. + $dbw->commit( __METHOD__, 'flush' ); + } $this->mId = $dbw->selectField( 'user', 'user_id', array( 'user_name' => $this->mName ), __METHOD__ ); $loaded = false; -- 2.20.1