-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V8: Hard coded "image" type in media picker value converter causes YSOD #6034
V8: Hard coded "image" type in media picker value converter causes YSOD #6034
Conversation
Ah Kenn. Nice find and nice fix. Thanks for the pics! We'll take a look and let you know if we need anything. Em |
It's worth noting the bug shows up using just the default media types if you have allowed folder selection and select a folder and an image then trying to get this value causes an error when it tries to convert Folder to Image |
👍 👍 👍 |
I think this might have been a breaking change. Upgrading a site from 8.1.3 to 8.1.4 means that any single image media picker throws an error if using Models Builder as the returned type is no longer a Image type instead it's IPublishedContent. The results are if you are accessing any model explicit properties then it now YSODs and a cast is required. e.g:
This is what I had to update to
|
It seems so :-( investigating I've marked the issue with If I understand correctly this happens on custom media types? Or all media types? |
This issue for me occurred when I had a Media Picker set to only pick a single Image. The Property Value Converter would convert the property to type Image explicitly instead of IPublishedContent. The only thing that's "custom" is that the default media type Image had had an additional property added to it. I suspect if you were accessing properties such as File Extension / Size (which are default on Image / Media) you'd have the same issue as IPublishedContent doesn't have those properties. |
Unfortunately, it also breaks querying for default properties like |
The workaround as mentioned by @NikRimington does work and will keep working when this change is reverted, which I think might be the correct thing to do for 8.1.5 while we rethink how the original issue can be fixed. However, it will cause pain again down the line. So I am not sure how we can fix it nicely without forcing people to do a forced cast to get property values. That is not very.. friendly. |
For people using Models Builder... the easiest solution is to force-implement the property in a partial, and cast the returned value to :( |
Also experiencing this issue - exact steps as @NikRimington above: all media pickers set to only return images (regardless of singular or multiple) fail to cast the value to @zpqrtbnk's solution is a decent one, but in my case the site has 40+ content types with an image picker on most... A little laborious sadly... In lieu of a scaleable fix here, I'm going to re-introduce the Media Picker converter to my SuperValueConverters package and override the core converter - hopefully this might help others in the same position too until a "proper" fix exists :-) |
Just note that the previous version of the property value converter has a serious error in it, it should never have returned all picker media items as type To summarize the issue, as I understand it now:
|
@nul800sebastiaan I slightly disagree with your statement that the behaviour is "completely inconsistent with any other pickers" - while the MNTP (for example) does always return I think the best approach here is having a real way to determine if a media type is an "image" - as pointed out in this thread, that's currently determined by whether a media item has a specific property on it... I'm doing a bit of digging to see if there's a nice way to determine if a media type might have a "thumbnail" |
Fair enough, however, always returning |
Indeed - I was a little too trigger happy with posting ;-) Updated my comment a bit. Think we can find a nice-ish way to determine what type to return, Nested Content style |
But even if a media type has a "thumbnail" it could absolutely still be a custom media type with custom properties. I hope we can reliably (non-hacky) find the correct type, but as far as I understand it now, I don't think we can. |
Just like @kjac mentioned, 'Pick only images' allows picking all media types that have a thumbnail. This is determined by checking whether the Umbraco-CMS/src/Umbraco.Core/Configuration/UmbracoSettings/ContentImagingElement.cs Lines 8 to 18 in 853087a
So this means you can also select the default |
As @ronaldbarendse and @kjac have pointed out, the thumbnail is used as the criteria for determining an "image" currently in the backoffice - so this would seem a sensible flag to check and see if the media type supports? Or we could determine an "image" by a media type that's The logic could be something like:
...Which facilitates the OOTB behaviour (returning |
@callumbwhyte As an image is determined by the file extension of the Besides, having the return type change when you add another custom media type (without changing the settings of the media picker) would result is very strange behavior. A better solution would be to specify the allowed media types in the settings and if there's only one selected, use that as return type. There's some discussion about extending existing pickers with features from MNTP and this is already mentioned by @kjac: #6181 (comment). To guarantee the picked items are of a specific type, you can always use |
The required changes to fix this are now done, but the class needs some cleanup:
To make inheriting the PVC easier, maybe also change:
|
Prerequisites
If there's an existing issue for this PR then this fixes #6033
Description
If you configure a media picker to pick only images, the media picker value converter assumes that all picked elements in the media picker are of a content type with the alias
Image
(which is the default "Image" media type).This is handy as you can access the built-in image properties of
Image
likeUmbracoHeight
andUmbracoWidth
directly without having to cast it or use e.g..Value<int>("umbracoHeight")
.Unfortunately this hard coded content type alias also results in a YSOD when rendering, if an editor has picked another "image" media type - e.g. if you have a custom "image" media type alongside the built-in one. Here's a GIF that demonstrates it:
Clearly the media picker doesn't prevent the user from selecting other media types, as long as they have a thumbnail (which qualifies them as "images") - and nor should it. However... this needs to be mirrored in the media value converter; it can't assume that the value is made up solely by
Image
items when it's in "only images" mode.This PR removes this assumption from the value converter. When it's applied you're able to pick and render different "image" media types:
The value converter now always returns
IEnumerable<IPublishedContent>
if the media picker is configured to allow multiple selected items, orIPublishedContent
if it is only allowed to pick one - just like the rest of the content pickers.This both fixes #6033 and ensures that the media picker works the way it is documented.
Breaking change?
This isn't strictly a breaking change from a code perspective. But it probably qualifies as a behavioral breaking change, as it may break implementations that access the
Image
content type properties (UmbracoHeight
,UmbracoWidth
etc.) directly on the picked items of a media picker in "only images" mode.Testing this PR
imagePicker
.