leekelleher / umbraco-contentment

Contentment for Umbraco - a state of happiness and satisfaction
https://marketplace.umbraco.com/package/umbraco.community.contentment
Mozilla Public License 2.0
155 stars 70 forks source link

[v3.0] Failing generating models when changing property property editor #176

Closed bjarnef closed 2 years ago

bjarnef commented 2 years ago

Which Contentment version are you using?

3.0.0

Which Umbraco version are you using? For example: 8.14.1 - don't just write v8

9.0.1

Bug summary

I am not sure if this issue is a bug in Contentment or it may be a Umbraco core issue.

However I had a existing datatype using radiobutton list and changed property editor to use [Contentment] Data List.

When I re-generated models, the model generation failed and I noticed these errors in log file:

{"@t":"2021-10-25T13:30:35.3512427Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001DF","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":31,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"682d7889-a489-4298-bee8-ddbff1d7a0e7","HttpRequestNumber":7,"HttpSessionId":"dfdef498-0c24-ccb8-9862-2e24402bea2a"}
{"@t":"2021-10-25T13:30:36.4993432Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001E3","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":31,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"1b9e614d-9f90-45b8-be41-c605e26284ff","HttpRequestNumber":8,"HttpSessionId":"a63717eb-1b1f-d2ed-c24f-3a4103c8062d"}
{"@t":"2021-10-25T13:30:38.6210026Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001E7","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":41,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"57c7584f-31e6-4e9c-bb45-26a119fe74b7","HttpRequestNumber":9,"HttpSessionId":"d2e010f0-fbc6-635a-3bfd-df2f3740d505"}
{"@t":"2021-10-25T13:30:40.0273770Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001EB","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":59,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"268d2605-32c8-4b62-9457-a3556195a069","HttpRequestNumber":10,"HttpSessionId":"e249e6dd-1ed5-fea5-391f-7df953ce7ec5"}
{"@t":"2021-10-25T13:30:48.7331004Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001F1","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":12,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"7e17b53a-6dde-4297-a8e9-4d0cece4ad09","HttpRequestNumber":11,"HttpSessionId":"49d01c4e-d49f-dad9-6483-4c83839e47ec"}
{"@t":"2021-10-25T13:30:49.7012205Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:000001F5","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":12,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"13dcb90c-5603-44ca-a730-0618ac399160","HttpRequestNumber":12,"HttpSessionId":"2533b21a-1e20-aea3-d5b8-233221d2da07"}
{"@t":"2021-10-25T13:30:56.2623489Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:00000201","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":63,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"80a0b019-7e87-4be9-a4fc-e9925c2d6866","HttpRequestNumber":13,"HttpSessionId":"d54e5a1f-eb82-473e-f91c-22da5191421f"}
{"@t":"2021-10-25T13:30:57.8133529Z","@mt":"Could not find a value for configuration field '{ConfigField}'","@l":"Warning","ConfigField":"preview","SourceContext":"Umbraco.Cms.Core.Models.Mapping.DataTypeMapDefinition","ActionId":"2eef8bc2-65e5-48d6-bf31-a53eba71d4ab","ActionName":"Umbraco.Cms.Web.BackOffice.Controllers.DataTypeController.GetById (Umbraco.Web.BackOffice)","RequestId":"0HMCNNDPSPKGD:00000205","RequestPath":"/umbraco/backoffice/umbracoapi/datatype/GetById","ConnectionId":"0HMCNNDPSPKGD","ProcessId":18156,"ProcessName":"UmbracoProject","ThreadId":55,"AppDomainId":1,"AppDomainAppId":"65ffeee9778a120d6cbdf3a5f87bfe043e30dcbe","MachineName":"LAPTOP-TVMJ2DRH","Log4NetLevel":"WARN ","HttpRequestId":"904af8b3-e83b-40ac-831d-09e074ebf18e","HttpRequestNumber":14,"HttpSessionId":"0c194f8a-5991-3d7f-4716-ad6c0b3489f7"}

I have instead deleted the datatype instance from scratch using [Contentment] Data List property editor.

I am using ModelsBuilder SourceCodeManual models mode.

Steps to reproduce

public enum Alignment
{
    [DataListItem(Icon = "align-left")]
    [EnumMember(Value = "left")]
    Left,

    [DataListItem(Icon = "align-center")]
    [EnumMember(Value = "center")]
    Center,

    [DataListItem(Icon = "align-right")]
    [EnumMember(Value = "right")]
    Right
}

Expected result / actual result

No response

Do you have Umbraco ModelsBuilder enabled?

What browsers are you seeing the problem on?

Chrome

leekelleher commented 2 years ago

@bjarnef Interesting, a similar scenario was mentioned here: https://github.com/leekelleher/umbraco-contentment/discussions/173#discussioncomment-1509614

I believe it's an Umbraco bug. In that a Content Type seems to cache the Property Editor alias, so that when a DataType is modified, e.g. the Property Editor is changed, the Content Type still references the old one. The only way it appears to invalid it is to open the Content Type and re-save it.

bjarnef commented 2 years ago

@leekelleher yeah, it may be related, but not sure if the issue is the same. I tried deleting the original datatypes, create new [Contentment] Data List datatypes (which currently not is used on any document types) and saved the document types which used the original datatypes.

But it seems I still get the Could not find a value for configuration field '{ConfigField}' errors in log. And because it fails it seems to fail generating at lot of different models, where most of these didn't reference these settings datatype at all 🙈

Then I have to discard the changes and re-build to start application again 🤐

So yeah, it is weird 🙄😛 https://github.com/umbraco/Umbraco-CMS/blob/v9/contrib/src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs#L179-L180

Furthermore is isn't useful to log "ConfigField" - I think it actually should log the name of the field 😅

bjarnef commented 2 years ago

@leekelleher I removed all Contentment datatype instances and the models generating works.

However when I add a new datatype instance e.g. "Text Alignment" using Alignment enum mentioned before, the models generation seems to fail again. 🤔

leekelleher commented 2 years ago

@bjarnef To clarify, are you saying that the ModelsBuilder generation always throws an error for Contentment data-types? Regardless of changing the doctype's property?

bjarnef commented 2 years ago

@leekelleher yes, it seeems so. I removed the original datatypes instances and also the properties from the document types. Afterwards I removed the Contentment specific datatype I had created.

When I generate models all is good, but when I then create a new datatype "Text Alignment" using the [Contentment] Data List and Alignment enum and not add this the any document types yet, but generate models it seems to fail again and log is showing Could not find a value for configuration field '{ConfigField}'.

I tried refreshing the various caching from NuCache dashboard just to see if that made a difference, but unfortunately not.

bjarnef commented 2 years ago

Okay, I had a few Contentment datatypes, which I deleted again.. but still got the errors.

However when was browsing content I noticed this error on a Testimonial block (using Block List editor).

image

StackTrace:

at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Umbraco.Cms.Web.BackOffice.ModelBinders.FromJsonPathAttribute.JsonPathBinder.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BinderTypeModelBinder.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

This block was using a settings element type with a "Layout" property, which used Contentment Datalist and enum data source. I re-saved the element type and will check further.

bjarnef commented 2 years ago

If I remove the block and try to insert it again I get the same error. I wonder if any of the serialization/deserialization could conflict with Umbraco core? 🤔 https://github.com/leekelleher/umbraco-contentment/blob/develop/src/Umbraco.Community.Contentment/Web/Serialization/PublishedContentContractResolver.cs

Unfortunately I had to uninstall Contentment in this specific project for now since it seemed to cause issues with generation of modes, but I will probably try again sometime later or in a test site 🤗

leekelleher commented 2 years ago

The PublishedContentContractResolver shouldn't be an issue. As far as I'm aware there isn't any auto-discovery for JSON Contract Resolvers in Umbraco? It'd only be used if explicitly set.

I'll try to reproduce the ModelsBuilder issue during this week, and I'll feedback on here.

bjarnef commented 2 years ago

Even though I have uninstalled Contentment I get the error in https://github.com/leekelleher/umbraco-contentment/issues/176#issuecomment-951121196 where it has a property using MNTP.

If I change to a textarea I don't see any specific value in the property and submit from block overlay doesn't fail. However going back to MNTP again makes it fail again 😬🙈

bjarnef commented 2 years ago

@leekelleher ahh the the log actually show the "ConfigField" as a separate property with value "preview".

It seems it may be an issue with this "preview" config field. https://github.com/leekelleher/umbraco-contentment/blob/develop/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs#L87-L92

leekelleher commented 2 years ago

@bjarnef Can we clarify what the issue is here, as I'm confused.

These Could not find a value for configuration field '{ConfigField}' errors are actually warnings in the log file, right? I mean, I don't want them there, but they aren't breaking anything?

Or is it the JsonSerializerException? and to reproduce that, do I need to set-up a Block List editor with ElementTypes (containing Data List editors?)

bjarnef commented 2 years ago

@leekelleher yes, I think these are just warnings and not specific related to this issue.

Actually I think it is different issue. I removed Contentment package from the project for now, but still get the JSON errors. It seems to be related to MNTP where some previous selected content nodes no longer are rendered in the property editor view using <umb-node-preview>.

I noticed I started getting POST errors from entity resource: https://github.com/umbraco/Umbraco-CMS/issues/11448

I am not sure what cause the error though, maybe a bug in Umbraco v9.0.1, Umbraco Forms or other Cloud specific logic.

bjarnef commented 2 years ago

@leekelleher I gave it another try with Contentment v3.0.1, but I can't really reproduce this now. I could switch property editors of existing datatypes and the models are generated.

bjarnef commented 2 years ago

Okay, it does seem to cause issues if changing property editor of existing datatypes and deploy this to Umbraco Cloud:

Local environment

image

Live environment

image

It seems to happen because the assets for some reason isn't registred:

image

bjarnef commented 2 years ago

I can see various controllers has Umbraco.Community.Contentment.Services.DevMode injected as devModeService, but I can't see where it is registred? https://github.com/leekelleher/umbraco-contentment/blob/dev/v3.x/src/Umbraco.Community.Contentment/DataEditors/DataList/data-list.editor.js#L11-L12

Okay, it seems to be a hidden feature, which even GitHub search can't find 😅 here https://github.com/leekelleher/umbraco-contentment/blob/develop/src/Umbraco.Community.Contentment/DataEditors/_/_dev-mode.js

bjarnef commented 2 years ago

I think the missing registred services and controllers may be an issue with Smidge which are bundling the assets on Umbraco Cloud, but not locally. I have also noticed this started happening for my own controllers used the block custom views and this where the external login providers are missing: https://github.com/umbraco/Umbraco.Cloud.Issues/issues/476#issuecomment-964857593

leekelleher commented 2 years ago

I get a feeling that Smidge is attempting to minify Contentment's already minified JS. I thought I'd tested for this, but will take another look.

leekelleher commented 2 years ago

@bjarnef I've separated out the v9/Smidge issue (which I believe is caused when debug=false on v9) to #185.

With the original issue, e.g. "Failing generating models when changing property property editor". Am I correct in thinking that is no longer an issue? (I feel like there were a few things going on in this thread, so a little lost what I should be concerned with. 😅 )

bjarnef commented 2 years ago

@leekelleher yeah, I couldn't reproduce the second time I tried the package. Maybe it was due the build errors in v3.0.0 which was fixed in v3.0.1

bjarnef commented 2 years ago

@leekelleher I think the JS errors was caused by another JS asset not being bundled due an error, which seemed the cause other JS assets not being registered/bundled.

See: https://github.com/bergmania/Bergmania.OpenStreetMap/issues/14 https://github.com/Shazwazza/Smidge/issues/132

RE the "other" issue with failing generating models. I can generate models, however when I then re-saved a datatype using e.g. Contentment Datalist .. and clicking "Generate Models" in ModelsBuilder dashboard it then run for a while until it seems to fail generating models.

However when running through IIS Express it didn't seem to be an issue.

https://user-images.githubusercontent.com/2919859/141690042-21b9cc29-b041-4a8c-a593-c0563a0e6e76.mp4

I suspect it is an issue when running dotnet watch run as it isn't an issue with dotnet run.

https://user-images.githubusercontent.com/2919859/141690207-33ff376b-880a-4a77-be3c-75c517158a47.mp4

It seems from the command it detect a change and then start building project, but before all models are generated I guess.

watch : Exited
watch : File changed: C:\VSProjects\my-project-v9\UmbracoCloud\src\MyProject.Core\Models\BaseColorTheme.generated.cs
watch : Started
Building...
C:\VSProjects\my-project-v9\UmbracoCloud\src\MyProject.Core\Extensions\PublishedContentExtensions.cs(9,23): error CS0246: The type or namespace name 'HomePage' could not be found (are you missing a using directive or an assembly reference?)
...
bjarnef commented 2 years ago

The JSON exception also doesn't seem to be related to Contentment, but may be a bug in Umbraco core. See: https://github.com/umbraco/Umbraco-CMS/issues/11448 https://github.com/umbraco/Umbraco-CMS/issues/11631