Also since this can only happen when a course is imported through management command as in case of import through studio the course_id remains same, so we can move (#L179 - #L205) inside the condition 
```if target_location_namespace is None:``` since target_location_namespace is None in case of management command.