Fix loop error when DEBUG is True