umbraco / Umbraco.Deploy.Issues

1 stars 0 forks source link

Umbraco.Deploy.Cloud breaks a tree added using Konstrukt #160

Closed philipdanielhayton closed 1 year ago

philipdanielhayton commented 1 year ago

Reproduction

Bug summary

I have an Umbraco Cloud project that uses Vendr for eCommerce. We need to add custom nodes to the stores within the 'Commerce' section and are using the Konstrukt package to do so. It works fine until I enable Umbraco.Deploy.Cloud, after which it starts throwing an error whenever I navigate to the custom subtree.

Specifics

I've tested this on two projects and it happens on both:

Upon expanding the store tree (with Umbraco.Deploy.Cloud enabled) it will throw the following error:

image

at Umbraco.Deploy.UI.Tree.TreeIntegration.GetTreeAlias(String treeAliasFromNotification, FormCollection queryString)
   at Umbraco.Deploy.UI.Tree.TreeIntegration.UpdateNodesForDeploy(TreeNodesRenderingNotification notification)
   at Umbraco.Deploy.UI.Tree.TreeIntegrationNotificationHandler.Handle(TreeNodesRenderingNotification notification)
   at Umbraco.Cms.Core.Events.NotificationHandlerWrapperImpl`1.<>c__DisplayClass0_0.<Handle>b__1(INotification theNotification)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishCore(IEnumerable`1 allHandlers, INotification notification)
   at Umbraco.Cms.Core.Events.NotificationHandlerWrapperImpl`1.Handle(INotification notification, ServiceFactory serviceFactory, Action`2 publish)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishNotification(INotification notification)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishAsync[TNotification](TNotification notification, CancellationToken cancellationToken)
   at Umbraco.Cms.Web.BackOffice.Trees.TreeControllerBase.GetNodes(String id, FormCollection queryStrings)
   at Konstrukt.Web.Events.Handlers.InjectKonstruktVirtualSubTrees.<>c__DisplayClass8_0.<<HandleAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Konstrukt.ScopedExecutionContext.ExecuteAsync(Func`3 action, CancellationToken cancellationToken)
   at Konstrukt.Web.Events.Handlers.InjectKonstruktVirtualSubTrees.HandleAsync(TreeNodesRenderingNotification notification, CancellationToken cancellationToken)
   at Umbraco.Cms.Core.Events.EventAggregator.PublishCoreAsync(IEnumerable`1 allHandlers, INotification notification, CancellationToken cancellationToken)
   at Umbraco.Cms.Web.BackOffice.Trees.TreeControllerBase.GetNodes(String id, FormCollection queryStrings)
   at lambda_method911(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Steps to reproduce

  1. Create a new Umbraco project (v10 or v11)
  2. Install nuget package Vendr
  3. Run the project and open Umbraco
  4. Goto Settings > Vendr > Right click on Stores and create a new store (call it anything)
  5. Click onto the new Store, click on the Permissions tab in the top right hand corner. Set the toggle for Administrators to true and click save.
  6. Goto Users > Groups > Administrators and add 'Commerce' to allowed sections
  7. Refresh the browser
  8. Navigate Commerce, expand the store you created earlier. Note that there is no child node called 'Assets'.
  9. Install nuget package Konstrukt
  10. Add the Asset.cs and the Startup.cs code below to your project
  11. Run the project, navigate to Commerce > Store, notice that there is now a node called Assets.
  12. Now install Umbraco.Deploy.Cloud
  13. Run the project, try navigating to Commerce > Store, when you expand the store it will throw an error complaining that it can't find an alias for the tree.
Asset.cs

    public class Asset
    {
        public Guid Id { get; set; }
        public Guid StoreId { get; set; }
        public Guid? ProductId { get; set; }
        public string? InternalRef { get; set; }
    }
Startup.cs

           services.AddUmbraco(_env, _config)
                .AddBackOffice()
                .AddWebsite()
                .AddKonstrukt(k =>
                {
                    k.WithSection("commerce", sectionConfig => sectionConfig
                        .WithTree("vendr", treeConfig => treeConfig

                            .AddVirtualSubTreeAfter(ctx => Guid.TryParse(ctx.Source.Id, out _), tn => tn.Name == "Analytics",
                                virtualTreeConfig => virtualTreeConfig
                                    .AddCollection<Asset>(x => x.Id, x => x.StoreId, "Notification", "Notifications",
                                        "A product notification", "icon-bell", "icon-bell", collectionConfig => collectionConfig
                                            .SetNameFormat(p => p.InternalRef)
                                            .DisableCreate()
                                    )
                            )

                        )
                    );
                })

Expected result

I wouldn't have expected Umbraco Deploy to cause any issues with this functionality whatsoever.

Actual result

It throws the error above.

AndyButland commented 1 year ago

Thanks for letting us know about this @philipdanielhayton. Please see my comment on the Konstrukt tracker for the background and what I looked at for a workaround.

On the Deploy side we'll make an update to handle this situation in our tree rendering notification handler to avoid the exception, which will be in the next patch releases.

jemayn commented 1 year ago

Hey @AndyButland

Do you have a prerelease NuGet feed or anything like that where we could get our hands on Deploy 11.0.2? A bit annoying to get a global error in the backoffice šŸ˜…

AndyButland commented 1 year ago

Yes, I've pushed it up to Umbraco's nightly feed now, which is at: https://www.myget.org/F/umbraconightly/api/v3/index.json

Possibly after a bit of time for caches to update, you should find version 11.0.2--preview.3.g87bd05d there.

jemayn commented 1 year ago

Tyvm Andy! It works wonderfully šŸ™‚

philipdanielhayton commented 1 year ago

Awesome, thanks @AndyButland I really appreciate you guys jumping on that so quickly. I'll update my project later this week.