From 458b95fded703fd6defde5e5d5cad54d7af3f67e Mon Sep 17 00:00:00 2001 From: Oleg Zhuk Date: Wed, 18 Sep 2024 14:46:20 +0200 Subject: [PATCH] VCST-1845: Indexing fails due to a null reference exception (#744) fix: Product index document builder fails when a product has an editorial review (description) with a null type or language code. --- .../Search/Indexing/ProductDocumentBuilder.cs | 2 +- .../Search/ProductAssociationSearchService.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/VirtoCommerce.CatalogModule.Data/Search/Indexing/ProductDocumentBuilder.cs b/src/VirtoCommerce.CatalogModule.Data/Search/Indexing/ProductDocumentBuilder.cs index 429657547..da5a8e5bf 100644 --- a/src/VirtoCommerce.CatalogModule.Data/Search/Indexing/ProductDocumentBuilder.cs +++ b/src/VirtoCommerce.CatalogModule.Data/Search/Indexing/ProductDocumentBuilder.cs @@ -245,7 +245,7 @@ protected virtual void IndexDescriptions(IndexDocument document, IList !string.IsNullOrEmpty(x?.Content))) { - var descriptionField = $"description_{review.ReviewType.ToLowerInvariant()}_{review.LanguageCode.ToLowerInvariant()}"; + var descriptionField = $"description_{review.ReviewType?.ToLowerInvariant() ?? "null"}_{review.LanguageCode?.ToLowerInvariant() ?? "null"}"; document.Add(new IndexDocumentField(descriptionField, review.Content, IndexDocumentFieldValueType.String) { IsRetrievable = true, IsCollection = true }); } } diff --git a/src/VirtoCommerce.CatalogModule.Data/Search/ProductAssociationSearchService.cs b/src/VirtoCommerce.CatalogModule.Data/Search/ProductAssociationSearchService.cs index 1bf211b60..ead570964 100644 --- a/src/VirtoCommerce.CatalogModule.Data/Search/ProductAssociationSearchService.cs +++ b/src/VirtoCommerce.CatalogModule.Data/Search/ProductAssociationSearchService.cs @@ -23,7 +23,7 @@ public ProductAssociationSearchService(Func catalogRepositor _platformMemoryCache = platformMemoryCache; } - public Task SearchProductAssociationsAsync(ProductAssociationSearchCriteria criteria) + public async Task SearchProductAssociationsAsync(ProductAssociationSearchCriteria criteria) { if (criteria == null) { @@ -31,7 +31,7 @@ public Task SearchProductAssociationsAsync(Produ } var cacheKey = CacheKey.With(GetType(), "SearchProductAssociationsAsync", criteria.GetCacheKey()); - return _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => + return await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) => { cacheEntry.AddExpirationToken(AssociationSearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory.TryCreateInstance();