Use safe_find_or_create_by in Seed::Environment (prevent RecordNotUnique)
The following discussion from !18827 (closed) should be addressed:
-
@ayufan started a discussion: @dosuken123
It seems that we should create and retry as early as possible with the
retry
onActiveRecord::RecordNotUnique
.We want to do it to ensure that object is created.
Otherwise the creation of environment will be likely done in big transaction later and I believe that we don't want to do it.
def to_resource find_environment || ::Environment.create(attributes) rescure ActiveRecord::RecordNotUnique retry end
I think we effectively need this.
Edited by Shinya Maeda