From b2f87f66fd725a2b7f76d940c83310eb053eb8f8 Mon Sep 17 00:00:00 2001 From: Zeegaan Date: Wed, 6 Jul 2022 15:05:43 +0200 Subject: [PATCH] Fix up User repository --- .../Repositories/Implement/UserRepository.cs | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs index 5bfb6c0bda..80b54f6e2e 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/UserRepository.cs @@ -377,14 +377,30 @@ SELECT 4 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE userDisabled = 0 var groupIds = user2Groups.Select(x => x.UserGroupId).ToList(); // get groups + // We wrap this in a try-catch, as this might throw errors when you try to login before having migrated your database + Dictionary groups; + try + { + sql = SqlContext.Sql() + .Select() + .From() + .WhereIn(x => x.Id, groupIds); - sql = SqlContext.Sql() - .Select() - .From() - .WhereIn(x => x.Id, groupIds); + groups = Database.Fetch(sql) + .ToDictionary(x => x.Id, x => x); + } + catch(Exception e) + { + Logger.LogDebug(e, "Couldn't get user groups. This should only happens doing the migration that add new columns to user groups"); - var groups = Database.Fetch(sql) - .ToDictionary(x => x.Id, x => x); + sql = SqlContext.Sql() + .Select(x=>x.Id, x=>x.Alias, x=>x.StartContentId, x=>x.StartMediaId) + .From() + .WhereIn(x => x.Id, groupIds); + + groups = Database.Fetch(sql) + .ToDictionary(x => x.Id, x => x); + } // get groups2apps