From 633b7875e7185f6d2969a5655d57ec30784e7a3f Mon Sep 17 00:00:00 2001 From: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> Date: Thu, 18 May 2023 11:26:29 +0300 Subject: [PATCH] Chore: Ignore unique constrain failure when creating the main organization (#68644) Chore: Ignore unique constrain failure when creatin the main organization --- pkg/services/sqlstore/user.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/services/sqlstore/user.go b/pkg/services/sqlstore/user.go index 19bcc640cd5..fd662fe85a2 100644 --- a/pkg/services/sqlstore/user.go +++ b/pkg/services/sqlstore/user.go @@ -157,6 +157,7 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro if has { return org.ID, nil } + ss.log.Debug("auto assigned organization not found") if ss.Cfg.AutoAssignOrgId != 1 { ss.log.Error("Could not create user: organization ID does not exist", "orgID", @@ -168,6 +169,11 @@ func (ss *SQLStore) getOrCreateOrg(sess *DBSession, orgName string) (int64, erro org.Name = mainOrgName org.ID = int64(ss.Cfg.AutoAssignOrgId) if err := sess.InsertId(&org, ss.Dialect); err != nil { + ss.log.Error("failed to insert organization with provided id", "org_id", org.ID, "err", err) + // ignore failure if for some reason the organization exists + if ss.GetDialect().IsUniqueConstraintViolation(err) { + return org.ID, nil + } return 0, err } } else {