Merge pull request #1981 from molecula/fb-1260-err-field-exists-2

need to wrap in conflictError to actually produce 409
This commit is contained in:
Matthew Jaffee 2022-03-16 00:40:05 -05:00 • committed by GitHub
commit 0d4ea1d991
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -536,7 +536,9 @@ func (i *Index) CreateField(name string, opts ...FieldOption) (*Field, error) {
// Create the field in etcd as the system of record. We do this without
// the lock held because it can take an arbitrary amount of time...
if err := i.persistField(context.Background(), cfm); err != nil {
if err := i.persistField(context.Background(), cfm); errors.Cause(err) == ErrFieldExists {
return nil, newConflictError(ErrFieldExists)
} else if err != nil {
return nil, errors.Wrap(err, "persisting field")
}
@ -585,7 +587,7 @@ func (i *Index) CreateFieldIfNotExists(name string, opts ...FieldOption) (*Field
}
// Create the field in etcd as the system of record.
if err := i.persistField(context.Background(), cfm); err != nil {
if err := i.persistField(context.Background(), cfm); err != nil && errors.Cause(err) != ErrFieldExists {
// There is a case where the index is not in memory, but it is in
// persistent storage. In that case, this will return an "index exists"
// error, which in that case should return the index. TODO: We may need
@ -644,7 +646,7 @@ func (i *Index) CreateFieldIfNotExistsWithOptions(name string, opt *FieldOptions
}
// Create the field in etcd as the system of record.
if err := i.persistField(context.Background(), cfm); err != nil {
if err := i.persistField(context.Background(), cfm); err != nil && errors.Cause(err) != ErrFieldExists {
// There is a case where the index is not in memory, but it is in
// persistent storage. In that case, this will return an "index exists"
// error, which in that case should return the index. TODO: We may need