diff --git a/pkg/api/resolver_mutation_tag.go b/pkg/api/resolver_mutation_tag.go index 51ea9d527..b23d99d00 100644 --- a/pkg/api/resolver_mutation_tag.go +++ b/pkg/api/resolver_mutation_tag.go @@ -37,7 +37,7 @@ func (r *mutationResolver) TagCreate(ctx context.Context, input models.TagCreate qb := models.NewTagQueryBuilder() // ensure name is unique - if err := manager.EnsureTagNameUnique(newTag.Name, tx); err != nil { + if err := manager.EnsureTagNameUnique(newTag, tx); err != nil { tx.Rollback() return nil, err } @@ -102,7 +102,7 @@ func (r *mutationResolver) TagUpdate(ctx context.Context, input models.TagUpdate } if existing.Name != updatedTag.Name { - if err := manager.EnsureTagNameUnique(updatedTag.Name, tx); err != nil { + if err := manager.EnsureTagNameUnique(updatedTag, tx); err != nil { tx.Rollback() return nil, err } diff --git a/pkg/manager/tag.go b/pkg/manager/tag.go index ac7809b3e..d26591f8c 100644 --- a/pkg/manager/tag.go +++ b/pkg/manager/tag.go @@ -7,18 +7,18 @@ import ( "github.com/stashapp/stash/pkg/models" ) -func EnsureTagNameUnique(name string, tx *sqlx.Tx) error { +func EnsureTagNameUnique(tag models.Tag, tx *sqlx.Tx) error { qb := models.NewTagQueryBuilder() // ensure name is unique - sameNameTag, err := qb.FindByName(name, tx, true) + sameNameTag, err := qb.FindByName(tag.Name, tx, true) if err != nil { _ = tx.Rollback() return err } - if sameNameTag != nil { - return fmt.Errorf("Tag with name '%s' already exists", name) + if sameNameTag != nil && tag.ID != sameNameTag.ID { + return fmt.Errorf("Tag with name '%s' already exists", tag.Name) } return nil