VE-1560: Fix for endless loop

More information here: https://gerrit.wikimedia.org/r/#/c/163273/

https://wikia-inc.atlassian.net/browse/VE-1560
Merge pull request #4893 from Wikia/VE-1560

VE-1560: Fix for endless loop