'1150' is not a valid udi, after content migration from v7.15.3 to 8.2
Hi
I have migrated the content of my site from Umbraco version 7.15.3 to 8.2.
During the upgrade, I was getting an error relating to using the unsupported Media Picker Property Editor. In order to complete the upgrade process, I had to delete MediaPicker Property Editor and assign MediaPicker2 to the data type I had on Umbraco version 7.15.3.
Having removed and then changed the Media Picker the content migration was successful. Then with the new site (v8.2) when I write a simple query like
var heroImage = content.Value("heroImage")
getting an error saying "String "1150" is not a valid udi."
I believe the value that is saved in the database it is still an integer whereas it should be UDI.
I really appreciate if anyone can help as I might be missing some obvious steps here or there is a possibility that the content migration has forgotten to convert int to UDI.
Changing the property editor in v7 doesn't change any of the existing data, so you will still have int IDs in the database. Then the migration to v8 will just see that you're using the UDI-based property editor and expect that all the stored data is UDIs.
There are plans to support the legacy property editors in the migration and convert int IDs to UDIs, but that doesn't help you right now if you've already run the migration.
I think the easiest solution would be to add a custom version of MediaPickerValueConverter to your site, modifying it to handle both int and UDI values. I haven't tested it, but I think something like this should work:
public class IntFriendlyMediaPickerValueConverter : Umbraco.Web.PropertyEditors.ValueConverters.MediaPickerValueConverter
{
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType,
object source, bool preview)
{
if (source == null) return null;
var nodeIds = source.ToString()
.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)
.Select(id =>
{
if (Udi.TryParse(id, out var udi))
{
return udi;
}
else if (Int32.TryParse(id, out var integer))
{
var item = _publishedSnapshotAccessor.PublishedSnapshot.Media.GetById(integer);
if (item != null)
return new GuidUdi(Constants.UdiEntityType.Media, item.Key);
}
return null;
})
.ToArray();
return nodeIds;
}
}
public class MyComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Register<IntFriendlyMediaPickerValueConverter>();
}
}
That should solve any problems rendering templates.
You may still have problems editing the migrated content, but I think it should only be a problem if you have a multi-valued media picker and add a new item. Removing and re-adding the existing item before adding the new one should get around that.
I have caught the formatException and used (int)GetProperty("image")?.GetSourceValue() - which seems to get the integer I'm looking for without an error!
'1150' is not a valid udi, after content migration from v7.15.3 to 8.2
Hi
I have migrated the content of my site from Umbraco version 7.15.3 to 8.2. During the upgrade, I was getting an error relating to using the unsupported Media Picker Property Editor. In order to complete the upgrade process, I had to delete MediaPicker Property Editor and assign MediaPicker2 to the data type I had on Umbraco version 7.15.3.
Having removed and then changed the Media Picker the content migration was successful. Then with the new site (v8.2) when I write a simple query like
var heroImage = content.Value("heroImage")
getting an error saying "String "1150" is not a valid udi."
I believe the value that is saved in the database it is still an integer whereas it should be UDI.
I really appreciate if anyone can help as I might be missing some obvious steps here or there is a possibility that the content migration has forgotten to convert int to UDI.
Many thank
Changing the property editor in v7 doesn't change any of the existing data, so you will still have int IDs in the database. Then the migration to v8 will just see that you're using the UDI-based property editor and expect that all the stored data is UDIs.
There are plans to support the legacy property editors in the migration and convert int IDs to UDIs, but that doesn't help you right now if you've already run the migration.
I think the easiest solution would be to add a custom version of
MediaPickerValueConverter
to your site, modifying it to handle both int and UDI values. I haven't tested it, but I think something like this should work:That should solve any problems rendering templates.
You may still have problems editing the migrated content, but I think it should only be a problem if you have a multi-valued media picker and add a new item. Removing and re-adding the existing item before adding the new one should get around that.
Thank you so much Steve, that has resolved the issue.
I have tried a few approaches to convert the id to UDI without writing any custom code but that wasn't successful.
I'm seeing this in a migrated site.
I have caught the formatException and used
(int)GetProperty("image")?.GetSourceValue()
- which seems to get the integer I'm looking for without an error!is working on a reply...