This is the comment in the catch statement--

            # If we've already created this enrollment in a separate transaction,
            # then just continue

This certainly won't be the case in the CMS code path. In reality, I don't see how it is ever an issue because the method get_or_create returns the registration if the user is already registered, and else create the registration. In other words, it is robust to call the method even if the user is already registered for the course. In fact, I have a unit test that does this to make sure there is no error.