GetDataItem() returns the wrong type

Posted by Community Admin on 04-Aug-2018 14:58

GetDataItem() returns the wrong type

All Replies

Posted by Community Admin on 07-Nov-2014 00:00

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?

Posted by Community Admin on 12-Nov-2014 00:00

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

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed