make rebuildstaging rebuild work again

was an issue with trying to loop through an iterator twice
Merge pull request #2696 from dimagi/fix-rebuildstaging

make rebuildstaging rebuild work again