GetDataItem() returns the wrong type
I stumbled across what appears to be a bug in Sitefinity 7.1.5200. I was making a call to DynamicContent.GetDataItem(Type, Guid), and accidentally passed in an incorrect guid from a different item type. I expected GetDataItem to return null, since the guid does not exist for the Type that I passed in. Instead, it found the guid in the system under a different item type, and returned that one. I drilled down to the code for GetDataItem and found that the Type parameter is not being used.
public override DynamicContent GetDataItem(Type itemType, Guid id)
DynamicContent dataItem = Queryable.SingleOrDefault<
DynamicContent
>(Queryable.Where<
DynamicContent
>(SitefinityQuery.Get<
DynamicContent
>((DataProviderBase) this, MethodBase.GetCurrentMethod()), (Expression<
Func
<DynamicContent, bool>>) (p => p.ApplicationName == this.ApplicationName && p.Id == id)));
if (dataItem == null)
throw new ItemNotFoundException(Res.Get<
ErrorMessages
>().ItemNotFound);
dataItem.Provider = (object) this;
this.ApplyViewPermissions(dataItem);
this.ApplyViewFieldPermissions((IDataItem) dataItem);
this.ApplyFilters((IDataItem) dataItem);
return dataItem;
Can someone please verify that this is incorrect behavior?
Hi Rich,
The method will indeed return the item even when a different object type is passed. The items are not filtered by the type parameter, which could lead to unexpected behavior. I have logged a bug regarding the issue, which can be reviewed here. I have also updated your Telerik points. As a workaround you can check whether the returned item type is of the one you expect, or make the query to get all items of those type and filter by the id and then to get the item in the memory.
Regards,
Nikola Zagorchev
Telerik