-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
postgres12 throws duplicate key value violates unique constraint "email_hash_pkey"
messages
#12287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So this should be fixed after v1.12.2 |
I am on 1.12.3 and my log still gets spammed with this. |
same here. |
So in the avatar linking code we do: Line 44 in e6baa65
On the assumption that a constraint violation just means that the insert fails so it's all fine. Clearly postgres demands that we actually add a if not exists there. |
I'm not certain if this would just stop postgres moaning here. We literally just want to store the precomputed avatar hash in the db if it's not there already. I'd really rather not have to write 4 different statements to get around excessive logging practices on the DB when we're just happily ignoring the error upstream. Could someone with a postgres setup try this to see if it stops the logging? diff --git a/models/avatar.go b/models/avatar.go
index 311d71462..c9ba2961e 100644
--- a/models/avatar.go
+++ b/models/avatar.go
@@ -41,7 +41,18 @@ func AvatarLink(email string) string {
Email: lowerEmail,
Hash: sum,
}
- _, _ = x.Insert(emailHash)
+ // OK we're going to open a session just because I think that that might hide away any problems with postgres reporting errors
+ sess := x.NewSession()
+ defer sess.Close()
+ if err := sess.Begin(); err != nil {
+ // we don't care about any DB problem just return the lowerEmail
+ return lowerEmail, nil
+ }
+ _, _ = sess.Insert(emailHash)
+ if err := sess.Commit(); err != nil {
+ // Seriously we don't care about any DB problems just return the lowerEmail - we expect the transaction to fail most of the time
+ return lowerEmail, nil
+ }
return lowerEmail, nil
})
return setting.AppSubURL + "/avatar/" + url.PathEscape(sum) |
[x]
):Description
postgres12 throws
duplicate key value violates unique constraint "email_hash_pkey"
messages.I am not sure when these messages started to appear, but it seems right after the upgrade from
1.12.1
to1.12.2
.Logs
The text was updated successfully, but these errors were encountered: