umbraco / Umbraco.Cms.Integrations

MIT License
36 stars 21 forks source link

Null reference in Content Delivery API for the Shopify Product Picker field #136

Closed SergeiPsarev closed 11 months ago

SergeiPsarev commented 11 months ago

When Shopify Picker Field is used in a document type and we pull the item through the Content Delivery API we get the following which looks like a bug.

Request: https://localhost:44362/umbraco/delivery/api/v1/content/item/7cf104a3-ad0b-408d-9daf-3a8dd7c3ac57

Response: { "type": "https://tools.ietf.org/html/rfc7231#section-6.6.1", "title": "System.NullReferenceException", "status": 500, "detail": "Object reference not set to an instance of an object.", "traceId": "00-687d76bb4c81982b642343591962ed64-ff4217946126f02a-00", "exception": { "details": "System.NullReferenceException: Object reference not set to an instance of an object.\r\n at Umbraco.Cms.Integrations.Commerce.Shopify.Editors.ShopifyProductPickerValueConverter.<>c.b6_2(ProductDto p)\r\n at System.Linq.Enumerable.WhereSelectListIterator`2.ToList()\r\n at Umbraco.Cms.Integrations.Commerce.Shopify.Editors.ShopifyProductPickerValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)\r\n at Umbraco.Cms.Infrastructure.PublishedCache.Property.<>c__DisplayClass25_0.gGetDeliveryApiObject|0()\r\n at Umbraco.Cms.Infrastructure.PublishedCache.Property.GetDeliveryApiDefaultObject(CacheValue cacheValues, Func1 getValue)\r\n at Umbraco.Cms.Infrastructure.PublishedCache.Property.GetDeliveryApiValue(Boolean expanding, String culture, String segment)\r\n at Umbraco.Cms.Core.DeliveryApi.ApiPropertyRenderer.GetPropertyValue(IPublishedProperty property, Boolean expanding)\r\n at Umbraco.Cms.Api.Delivery.Rendering.RequestContextOutputExpansionStrategy.<MapProperties>b__8_1(IPublishedProperty property)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](TSource[] source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer)\r\n at Umbraco.Cms.Api.Delivery.Rendering.RequestContextOutputExpansionStrategy.MapProperties(IEnumerable1 properties)\r\n at Umbraco.Cms.Api.Delivery.Rendering.RequestContextOutputExpansionStrategy.MapContentProperties(IPublishedContent content)\r\n at Umbraco.Cms.Core.DeliveryApi.ApiContentBuilderBase1.Build(IPublishedContent content)\r\n at Umbraco.Cms.Api.Delivery.Controllers.ByIdContentApiController.ById(Guid id)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location ---\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location ---\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)\r\n at Microsoft.AspNetCore.Routing.EndpointMiddleware.gAwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n at Umbraco.Cms.Web.Common.Middleware.BasicAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Umbraco.Cms.Web.BackOffice.Middleware.BackOfficeExternalLoginProviderErrorMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)\r\n at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)\r\n at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 114\r\n at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Umbraco.Cms.Web.Common.Middleware.PreviewAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestLoggingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, Boolean retry)\r\n at Umbraco.Forms.Web.HttpModules.ProtectFormUploadRequestsMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)\r\n at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>cDisplayClass6_1.<b1>d.MoveNext()\r\n--- End of stack trace from previous location ---\r\n at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)", "headers": { "Accept": [ "application/json" ], "Host": [ "localhost:44362" ], "User-Agent": [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" ], "Accept-Encoding": [ "gzip, deflate, br" ], "Accept-Language": [ "en" ], }, "path": "/umbraco/delivery/api/v1/content/item/7cf104a3-ad0b-408d-9daf-3a8dd7c3ac57", "endpoint": "Umbraco.Cms.Api.Delivery.Controllers.ByIdContentApiController.ById (Umbraco.Cms.Api.Delivery)", "routeValues": { "action": "ById", "controller": "ByIdContentApi", "id": "7cf104a3-ad0b-408d-9daf-3a8dd7c3ac57", "version": "1" } } }


_This item has been added to our backlog AB#33479_

acoumb commented 11 months ago

Hi @SergeiPsarev ,

Could you give me more details on the configuration you have? I have tested the delivery API, and could not replicate the issue. Here is a walkthrough of my test, please let me know what I'm doing different or missing.

Regards, Adrian

acoumb commented 11 months ago

Hi @SergeiPsarev , did you manage to check my last week's comment? Is this still an issue for you?

Regards, Adrian

SergeiPsarev commented 11 months ago

Hi @acoumb

For me it is no longer an issue because we got rid of the Shopify Picker Value converter (removed from DI) like this: builder.PropertyValueConverters().Remove();

Anyway it looks like it pulls all Shopify products (makes same "get all Shopify products" call for each Shopify Picker value) and doesn't cache them.... doesn't work for our headless architecture as we'd like to pull the list of Shopify products just once and not on Umbraco side but on Next.JS application side. Maybe I missed something while looking through the code but that was the impression, so combined with the error - we decided to get rid of the value converter.

Our configuration: image

acoumb commented 11 months ago

Hi @SergeiPsarev ,

Maybe you could try again once I release the patch version 1.1.3 with the update detailed here.

Adrian