umbraco / Umbraco.Commerce.Issues

17 stars 2 forks source link

'Umbraco.Commerce.Cms.Web.Api.Storefront.ValueConverters.StorefrontPricePropertyValueConverter' has already been detected as a converter for that property, and only one converter can exist for a property. #429

Closed konius closed 1 year ago

konius commented 1 year ago

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

12.1.2

Bug summary

Umbraco models fail to generate and there is a runtime error after upgrading to latest Umbraco Commerce 12.1.0.

Last generation failed with the following error:
Failed to build models.
Type 'Umbraco.Commerce.Cms.ValueConverters.PricePropertyValueConverter' cannot be an IPropertyValueConverter for property 'price' of content type 'productOptions' because type 'Umbraco.Commerce.Cms.Web.Api.Storefront.ValueConverters.StorefrontPricePropertyValueConverter' has already been detected as a converter for that property, and only one converter can exist for a property.

at Umbraco.Cms.Core.Models.PublishedContent.PublishedPropertyType.InitializeLocked()
at Umbraco.Cms.Core.Models.PublishedContent.PublishedPropertyType.Initialize()
at Umbraco.Cms.Core.Models.PublishedContent.PublishedPropertyType.get_ModelClrType()
at Umbraco.Cms.Infrastructure.ModelsBuilder.UmbracoServices.GetTypes(PublishedItemType itemType, IContentTypeComposition[] contentTypes)
at Umbraco.Cms.Infrastructure.ModelsBuilder.UmbracoServices.GetAllTypes()
at Umbraco.Cms.Infrastructure.ModelsBuilder.Building.ModelsGenerator.GenerateModels()
at Umbraco.Cms.Web.BackOffice.ModelsBuilder.ModelsBuilderDashboardController.BuildModels()

image

Specifics

Umbraco CMS 12.1.2 Umbraco Commerce 12.1.0

Steps to reproduce

Install both versions.

Expected result / actual result

Site to run without any errors.

github-actions[bot] commented 1 year ago

Hi there @konius!

Firstly, a big thank you for raising this issue. Every piece of feedback we receive helps us to make Umbraco better.

We really appreciate your patience while we wait for our team to have a look at this but we wanted to let you know that we see this and share with you the plan for what comes next.

We wish we could work with everyone directly and assess your issue immediately but we're in the fortunate position of having lots of contributions to work with and only a few humans who are able to do it. We are making progress though and in the meantime, we will keep you in the loop and let you know when we have any questions.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:

mattbrailsford commented 1 year ago

Thanks for reporting @konius I believe I know what the issue is here and will take a look at a solution.

In the meantime, I think a workaround might be to register the StorefrontAPI dependencies as documented here https://docs.umbraco.com/umbraco-commerce/reference/storefront-api#register-the-storefront-api-dependencies and that should resolve it as installing the storefront API dependencies should remove the old value converters.

konius commented 1 year ago

Yes, that did the trick.

Strange as I thought I tried following the guide, but maybe missed something.

mattbrailsford commented 1 year ago

@konius if you aren't using the storefront API you shouldn't really need to register those dependencies. The bug is that I didn't account for the fact that Umbraco auto loads value converters so it needs to explicitly remove the storefront value converters if a registration hasn't taken place.

The workaround works because registering the storefront dependencies, removes the old value converters and so leaves just the storefront ones.

If you aren't using the storefront API, it should be fine to add the dependencies for now as you can't use those API's unless you have setup an API key anyway.

I looked at this today so there will be a fix for this in the next patch release đź‘Ť

mattbrailsford commented 1 year ago

Fixed in 12.1.1