Describe the bug
We have a custom Reviews table that uses the Node Key (Guid) to map a review to a given umbraco node.
We also have a Context App created through the Umbraco UI builder to manage reviews on the node.
We were using a custom TypeConverter to map the UDI provided by UI Builder to a GUID and vice versa.
However after upgrading from 13.1.1 to version 13.1.5 and the conversion has stopped happening, so the Guid value is always default (0000-000000.... etc). The TypeConverter doesn't event seem to be getting called any more.
Do we need to be using a different approach when using a Guid as the foreign key now?
Steps To Reproduce
Steps to reproduce the behavior:
Create a custom database table that includes a umbraco node content key (Guid)
Create a repository to act as intermediary between the db table and UI builder
Create a context app that uses the repository created in (2), and use the umbraco node content key as the foreign key
Add a few entries into the database table for a specific node, just so you know there should be some results
Navigate to the node in Umbraco, flick to the context app, the results should be empty
If you put a breakpoint on the Repository.GetAllImpl method and inspect the whereClause, it should be passing a default Guid (0000-000...)
Expected behavior
Ideally, when using a Guid as a foreign key, Umbraco UI would automatically convert the UDI to a Guid, passing the correct Guid into the GetAllImpl whereClause.
However failing that, the old behavior should still work as it did in version 13.1.1. Whereby a custom TypeConverter can be implemented to handle the mapping.
Environment (please complete the following information):
Umbraco Version 13.3.2
Product Version 13.1.5 (previously 13.1.1)
Additional context
Here's the UdiToGuidConverter implementation mentioned above.
public class UdiToGuidConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(Udi) || sourceType == typeof(GuidUdi) || sourceType == typeof(string);
}
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
return Convert(value);
}
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
{
return destinationType == typeof(Guid);
}
public override object ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
{
return Convert(value);
}
private object Convert(object? value)
{
if (value is Udi udiValue)
return ConvertUdiToGuid(udiValue);
if (value is GuidUdi guidValue)
return guidValue.Guid;
if (value is string strValue)
return ConvertStringToGuid(strValue);
throw new NotSupportedException($"Cannot convert {value?.GetType()} to Guid.");
}
private Guid ConvertUdiToGuid(Udi udi)
{
return ((GuidUdi)udi).Guid;
}
private Guid ConvertStringToGuid(string strValue)
{
if (Guid.TryParse(strValue, out var guid))
return guid;
if (UdiParser.TryParse(strValue, out var _udi))
return ((GuidUdi)_udi).Guid;
throw new ArgumentException("Provided string cannot be parsed into Guid."); // Or another kind of handling
}
}
We register this in a composer on start up.
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddTransient<IReviewService, ReviewService>();
}
Describe the bug We have a custom Reviews table that uses the Node Key (Guid) to map a review to a given umbraco node.
We also have a Context App created through the Umbraco UI builder to manage reviews on the node.
We were using a custom TypeConverter to map the UDI provided by UI Builder to a GUID and vice versa.
However after upgrading from 13.1.1 to version 13.1.5 and the conversion has stopped happening, so the Guid value is always default (0000-000000.... etc). The TypeConverter doesn't event seem to be getting called any more.
Do we need to be using a different approach when using a Guid as the foreign key now?
Steps To Reproduce Steps to reproduce the behavior:
Expected behavior Ideally, when using a Guid as a foreign key, Umbraco UI would automatically convert the UDI to a Guid, passing the correct Guid into the GetAllImpl whereClause.
However failing that, the old behavior should still work as it did in version 13.1.1. Whereby a custom TypeConverter can be implemented to handle the mapping.
Environment (please complete the following information):
Additional context Here's the UdiToGuidConverter implementation mentioned above.
We register this in a composer on start up.
Here's our custom repository: