Fix 'reference before assignment error' or celery error