[fix] only do flask context if needed