umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.48k stars 2.69k forks source link

Null File Extensions in Data Type Throws Exception While Creating Media Item in Upgraded Project #16984

Open nackler opened 2 months ago

nackler commented 2 months ago

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

14.2.0

Bug summary

Upgraded a v13 project to v14. This does not happen on a fresh install of v14.

As a content editor - exception when creating a 'File' (not 'Image') media item in the media library with a file type of PDF. See call stack below.

I was able to get around what is essentially a null reference exception by running a SQL command that changes the stored configuration from "{"fileExtensions":null}" to "{}" for nodeId -90.

update umbracoDataType set config = '{}' where propertyEditorAlias = 'Umbraco.UploadField' and config = '{"fileExtensions":null}'

A new v14 install had the configuration as "{}" but my upgraded instance had "{"fileExtensions":null}" for the DataType config. Caveat: It is possible that a usync automatic import preserved what is now apparently an invalid value in my database.

This bug report is to perhaps help someone else in this situation or perhaps some more null handling can be added to FileUploadPropertyValueEditor.IsAllowedInDataTypeConfiguration so that fileUploadConfiguration.FileExtensions is checked for null before .Any gets called on it.

Another option would be to make the data change part of the upgrade data migration during upgrade if it isn't already.

Specifics

System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.TryGetNonEnumeratedCount[TSource](IEnumerable`1 source, Int32& count)
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at Umbraco.Cms.Core.PropertyEditors.FileUploadPropertyValueEditor.IsAllowedInDataTypeConfiguration(String extension, Object dataTypeConfiguration)
   at Umbraco.Cms.Core.PropertyEditors.TemporaryFileUploadValidator.Validate(Object value, String valueType, Object dataTypeConfiguration)+MoveNext()
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.ToList()
   at Umbraco.Cms.Core.PropertyEditors.DataValueEditor.Validate(Object value, Boolean required, String format)
   at Umbraco.Cms.Core.Services.PropertyValidationService.ValidatePropertyValue(IDataEditor editor, IDataType dataType, Object postedValue, Boolean isRequired, String validationRegExp, String isRequiredMessage, String validationRegExpMessage)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at Umbraco.Cms.Core.Services.ContentValidationServiceBase`1.ValidateProperty(ContentEditingModelBase contentEditingModelBase, IPropertyType propertyType, String culture, String segment)
   at Umbraco.Cms.Core.Services.ContentValidationServiceBase`1.HandlePropertiesValidationAsync(ContentEditingModelBase contentEditingModelBase, TContentType contentType)
   at Umbraco.Cms.Core.Services.MediaValidationService.ValidatePropertiesAsync(ContentEditingModelBase contentEditingModelBase, IMediaType mediaType)
   at Umbraco.Cms.Core.Services.ContentEditingServiceBase`4.ValidatePropertiesAsync(ContentEditingModelBase contentEditingModelBase, TContentType contentType)
   at Umbraco.Cms.Core.Services.ContentEditingServiceBase`4.MapCreate[TContentCreateResult](ContentCreationModelBase contentCreationModelBase)
   at Umbraco.Cms.Core.Services.MediaEditingService.CreateAsync(MediaCreateModel createModel, Guid userKey)
   at Umbraco.Cms.Api.Management.Controllers.Media.CreateMediaController.<>c__DisplayClass4_0.<<Create>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Umbraco.Cms.Api.Management.Controllers.Media.CreateMediaControllerBase.HandleRequest(Nullable`1 parentId, Func`1 authorizedHandler)
   at Umbraco.Cms.Api.Management.Controllers.Media.CreateMediaController.Create(CancellationToken cancellationToken, CreateMediaRequestModel requestModel)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, 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.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Umbraco.Cms.Web.Common.Middleware.BasicAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Umbraco.Cms.Api.Management.Middleware.BackOfficeExternalLoginProviderErrorMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 112
   at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Umbraco.Cms.Web.Common.Middleware.PreviewAuthenticationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Umbraco.Cms.Web.Common.Middleware.UmbracoRequestLoggingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.InterfaceMiddlewareBinder.<>c__DisplayClass2_0.<<CreateMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)

image

Steps to reproduce

Create a v13 project Upgrade it to v14 Upload a media item to the media library of type 'File' (I used a pdf)

image

When saving, you will get the exception 'Value cannot be null. (Parameter 'source')" in a pink validation error popup in the bottom right hand corner of the backoffice.

If you can't recreate this issue then maybe this was a situation exacerbated by uSync, in which case I probably did something wrong by not disabling usync during my upgrade and you can disregard.

Expected result / actual result

I expected that the media item would save, but instead the above exception occurred.

github-actions[bot] commented 2 months ago

Hi there @nackler!

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:

nackler commented 2 months ago

Ugh, I just realized it is also possible that I got into this situation by adding a file extension to the predefined 'file' datatype then removing it again, which might explain the switch from {} to {"fileExtensions":null} in the config. Maybe that is the real bug and this has nothing to do with an upgrade to v14. Sorry about the lack of clarity.