The Free Software Media System - Server Backend & API
Attach before updating/deleting to avoid DbUpdateConcurrencyException (#14746)
evan314159424682523961
diff --git a/Jellyfin.Server.Implementations/Users/UserManager.cs b/Jellyfin.Server.Implementations/Users/UserManager.csindex 3dfb14d716..d0b41a7f6b 100644--- a/Jellyfin.Server.Implementations/Users/UserManager.cs+++ b/Jellyfin.Server.Implementations/Users/UserManager.cs@@ -272,6 +272,7 @@ namespace Jellyfin.Server.Implementations.Usersvar dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);await using (dbContext.ConfigureAwait(false)){+ dbContext.Users.Attach(user);dbContext.Users.Remove(user);await dbContext.SaveChangesAsync().ConfigureAwait(false);}@@ -887,7 +888,8 @@ namespace Jellyfin.Server.Implementations.Usersprivate async Task UpdateUserInternalAsync(JellyfinDbContext dbContext, User user){- dbContext.Users.Update(user);+ dbContext.Users.Attach(user);+ dbContext.Entry(user).State = EntityState.Modified;_users[user.Id] = user;await dbContext.SaveChangesAsync().ConfigureAwait(false);}