Index: src/wp-includes/user.php
===================================================================
--- src/wp-includes/user.php	(revision 40557)
+++ src/wp-includes/user.php	(working copy)
@@ -1417,6 +1417,8 @@
 			return new WP_Error( 'invalid_user_id', __( 'Invalid user ID.' ) );
 		}
 
+		$userdata['user_login'] = $old_user_data->user_login;
+
 		// hashed in wp_update_user(), plaintext if called directly
 		$user_pass = ! empty( $userdata['user_pass'] ) ? $userdata['user_pass'] : $old_user_data->user_pass;
 	} else {
@@ -1442,7 +1444,7 @@
 	$user_login = trim( $pre_user_login );
 
 	// user_login must be between 0 and 60 characters.
-	if ( empty( $user_login ) ) {
+	if ( empty( $user_login ) && ! $update ) {
 		return new WP_Error('empty_user_login', __('Cannot create a user with an empty login name.') );
 	} elseif ( mb_strlen( $user_login ) > 60 ) {
 		return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
Index: tests/phpunit/tests/user/wpInsertUser.php
===================================================================
--- tests/phpunit/tests/user/wpInsertUser.php	(revision 0)
+++ tests/phpunit/tests/user/wpInsertUser.php	(working copy)
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * @group user
+ */
+class Tests_User_InsertUser extends WP_UnitTestCase {
+
+	/**
+	 * @ticket 40497
+	 */
+	public function test_wp_insert_user_can_updating_existing_user() {
+		$id = self::factory()->user->create( array(
+			'user_nicename' => 'oldname',
+		) );
+
+		$user = get_user_by( 'ID', $id );
+		$this->assertSame( $user->user_nicename, 'oldname' );
+
+		wp_insert_user( array(
+			'ID'            => $id,
+			'user_nicename' => 'newname',
+		) );
+
+		$user = get_user_by( 'ID', $id );
+		$this->assertSame( $user->user_nicename, 'newname' );
+	}
+}
