You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempt to access the .Children property of a work item that has more than 200 child items.
Here is the rule that is failing intermittently for us (when the work item posted happens to have more than 200 children...and before you ask, I'm not the one who decided to have work items with more than 200 children!).
.lang=C#
/*
*
* AutoClose update PBI states based on child items.
*
*/
var debug=false;
var areaPathFilter = "Federated Projects\\GregTest";
var appliesToWorkItemTypes = new[] {"Task", "Bug", "Milestone"};
var statesCausingParentClose = new[] {"Removed", "Done"};
var statesParentIsUnchangedIn = new[] {"Removed", "Done"};
var closedState = "Done";
if(debug && self.AreaPath != areaPathFilter)
{
logger.WriteInfo($"This rule is in debug mode, and therefore only applies to items in {areaPathFilter}");
logger.WriteInfo("Exiting");
return;
}
if (!appliesToWorkItemTypes.Contains(self.WorkItemType))
{
return $"Work item type was {self.WorkItemType}, so this rule will not be considered.";
}
var parent = self.Parent;
if (parent == null)
{
return $"Work item has no parent, so this rule will not be considered.";
}
var children = parent.Children;
if (children.All(c => statesCausingParentClose.Contains(c.State)))
{
if(!statesParentIsUnchangedIn.Contains(parent.State))
{
parent.State = closedState;
parent.History = "All work completed, auto-finishing: ";
logger.WriteInfo($"Aggregator changed {parent.WorkItemType} {parent.Id}: State = {parent.State}");
}
else
{
logger.WriteInfo($"Parent {parent.Id} has state {parent.State}. Parent was not changed.");
}
}
else
{
logger.WriteInfo($"Parent was not changed.");
}
return;
Expected behavior
A list of the children of the work item is returned.
Actual behavior
A 400 Bad Request is returned from the function, with the error:
One or more errors occurred. (VS403474: You requested 307 work items which exceeds the limit of 200)
Suspected cause
Looking into the code of the Aggregator, here's the Children property:
public IEnumerable<WorkItemWrapper> Children
{
get
{
if (ChildrenLinks != null && ChildrenLinks.Any())
{
var store = new WorkItemStore(_context);
return store.GetWorkItems(ChildrenLinks);
}
else
return new WorkItemWrapper[0];
}
}
And the GetWorkItems() method:
public IList<WorkItemWrapper> GetWorkItems(IEnumerable<int> ids)
{
_context.Logger.WriteVerbose($"Getting workitems {ids.ToSeparatedString()}");
return _context.Tracker.LoadWorkItems(ids, (workItemIds) =>
{
_context.Logger.WriteInfo($"Loading workitems {workItemIds.ToSeparatedString()}");
var items = _clients.WitClient.GetWorkItemsAsync(workItemIds, expand: WorkItemExpand.All).Result;
return items.ConvertAll(i => new WorkItemWrapper(_context, i));
});
}
GetWorkItemsAsync is doing the dirty work and seems to be the problem. This has been cited in the past as a limitation of GetWorkItemsAsync, and it may be that ADO introduced a limit to head off this problem. In any case, I would imagine it should be easy to correct by splitting the set of work item IDs into batches if there are more than 200 of them and combining the batches.
The text was updated successfully, but these errors were encountered:
Steps to reproduce
Aggregator CLI 0.9.2.
Attempt to access the
.Children
property of a work item that has more than 200 child items.Here is the rule that is failing intermittently for us (when the work item posted happens to have more than 200 children...and before you ask, I'm not the one who decided to have work items with more than 200 children!).
Expected behavior
A list of the children of the work item is returned.
Actual behavior
A 400 Bad Request is returned from the function, with the error:
Suspected cause
Looking into the code of the Aggregator, here's the
Children
property:And the
GetWorkItems()
method:GetWorkItemsAsync
is doing the dirty work and seems to be the problem. This has been cited in the past as a limitation ofGetWorkItemsAsync
, and it may be that ADO introduced a limit to head off this problem. In any case, I would imagine it should be easy to correct by splitting the set of work item IDs into batches if there are more than 200 of them and combining the batches.The text was updated successfully, but these errors were encountered: