diff --git a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs index e97b62b27..846e20f33 100644 --- a/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs +++ b/src/Orchard.Web/Modules/Orchard.Indexing/Services/IndexingTaskExecutor.cs @@ -160,6 +160,9 @@ namespace Orchard.Indexing.Services { .OrderBy(versionRecord => versionRecord.Id) .Take(ContentItemsPerLoop) .ToList() + // In some rare cases a ContentItemRecord without a ContentType can end up in the DB. + // We need to filter out such records, otherwise they will crash the ContentManager. + .Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null) .Select(versionRecord => _contentManager.Get(versionRecord.ContentItemRecord.Id, VersionOptions.VersionRecord(versionRecord.Id))) .Distinct() .ToList(); @@ -220,6 +223,9 @@ namespace Orchard.Indexing.Services { .OrderBy(x => x.Id) .Take(ContentItemsPerLoop) .ToList() + // In some rare cases a ContentItemRecord without a ContentType can end up in the DB. + // We need to filter out such records, otherwise they will crash the ContentManager. + .Where(x => x.ContentItemRecord != null && x.ContentItemRecord.ContentType != null) .GroupBy(x => x.ContentItemRecord.Id) .Select(group => new { TaskId = group.Max(task => task.Id), Delete = group.Last().Action == IndexingTaskRecord.Delete, Id = group.Key, ContentItem = _contentManager.Get(group.Key, VersionOptions.Latest) }) .OrderBy(x => x.TaskId)