Fix user profile writes on postgres conflicts
This commit is contained in:
@@ -277,7 +277,9 @@ func ensureBoundEmailAuthIdentityWithClient(
|
||||
).
|
||||
DoNothing().
|
||||
Exec(ctx); err != nil {
|
||||
return err
|
||||
if !isSQLNoRowsError(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
identity, err := client.AuthIdentity.Query().
|
||||
|
||||
@@ -916,6 +916,11 @@ func (s *AuthService) ensureEmailAuthIdentity(ctx context.Context, user *User, s
|
||||
).
|
||||
DoNothing().
|
||||
Exec(ctx); err != nil {
|
||||
if isSQLNoRowsError(err) {
|
||||
err = nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
logger.LegacyPrintf("service.auth", "[Auth] Failed to ensure email auth identity: user_id=%d email=%s err=%v", user.ID, email, err)
|
||||
return nil, false
|
||||
}
|
||||
|
||||
14
backend/internal/service/sql_errors.go
Normal file
14
backend/internal/service/sql_errors.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isSQLNoRowsError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
return errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), "no rows in result set")
|
||||
}
|
||||
Reference in New Issue
Block a user