I am using Sitecore 9.3 with Glass Mapper 5.8.177 and component A/B testing does not work for me.

I set up a simple component that works perfectly fine until I begin creating variants for A/B testing of this component. For both variants I am getting the "Data source is invalid." error. I saw this was an issue previously and there were some PR that was merged saying that this was fixed in the version I am using but it still does not seem to be working for me.

The problematic method is:

var datasource = MvcContext.GetDataSourceItem<T>();

which returns null.

After debugging it seems that the item is resolved correctly until the ItemVersionCountByRevisionTask, void Execute(ObjectConstructionArgs args) method is reached.

The condition below fails because the Revision field does not exist in the Item Fields

if (scContext != null 
    && options != null 
    && options.VersionCount 
    && scContext.Item != null 
    && scContext.Item.Fields[FieldIDs.Revision].GetValue(allowStandardValue: false).IsNullOrEmpty())
        args.Result = null;

Debugger shows that the scContext.Item.Fields do not contain the Revision field, that is why it returns null. The only field which is visible in my item while debugging is "__Originator"-{F6D8A61C-2F84-4401-BD24-52D2068172BC}. There are also no custom fields mapped as well.

I tried setting A/B testing also for different components - the same issue for all of them. All of the components inherit from StandardTemplate and Revision field is present on the items when I check that from Sitecore. Also, all of the components are being displayed and are working fine as long as no A/B testing is used.

When I check MvcContext.DataSourceItem value after MvcContext.GetDataSourceItem<T>(); it seems that the items were set correctly in the DataSourceItem, they are just unable to be mapped to a model.

Any ideas on what is happening here and how to resolve these issues would be more than welcome.

  • Make sure where there issue is, if you remove Glass from the equation, does your A/B test work ok?
    – Richard Seal
    Commented Nov 15, 2021 at 14:36

1 Answer 1


We have encountered exact the same problem with the null datasource in Sitecore v. 9.3 and Glass.Mapper v. 5.6.

As a workaround we have implemented our base Controller with the explicit datasource retrieval by id, language and version as follows:

var options = new GetItemByIdOptions(id)
    Language = language,
    Version = version
var datasource = SitecoreContext.SitecoreService.GetItem<TDatasource>(options);
if (datasource == null)
        options.Language = Sitecore.Context.Language;
        datasource = SitecoreContext.SitecoreService.GetItem<TDatasource>(options);

Where id, language and version we get from a RenderingContext.Rendering.DataSource string using a regular expression.

Then we inherited all our controllers from the base one to apply the datasource fix across all the concerned components. To begin with it will be enough to implement the fix only for components participating in the A/B testing.

Also it will be safe to ensure that both enableItemLanguageFallback and enableFieldLanguageFallback settings are set to true in the config file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.