-
Notifications
You must be signed in to change notification settings - Fork 11
Integrity error when adding e-mail that belongs to another user #10
Comments
So, the email property used to be unique_together with user. I could not recall the use case for that setup, and it seemed to me that Email addresses should be globally unique, which is why the model code stands as it is now. I am open to discussion on this, but I think the fix is to keep email addresses globally unique and to change this:
to this:
And get the user via the retrieved EmailAddress object. |
… already used by another user. This fixes scott2b#10
In doing so, you could be getting a different user than intended (that is: you search I'll create a code proposal in my branch. |
How this scenario can happen: |
This is fine for now. The logic will change a bit after changes to make user,email unique together to address issue #10. But, I think this is right, we don't want to allow unverified addresses to be set to primary.
@clemente sorry it's been a while. I'd like to get this issue cleaned up. If I understand correctly, if we were to have it that the user and email were unique-together, instead of the email globally unique, then this code change would not be needed. Does that seem right to you? |
Hi, that's right, unique-together of email+user makes sense, whereas unique of only email doesn't. |
But then:
The search you do is for user X and e-mail Y. If there's user Z with e-mail Y, you find 0 results, then you try to add (X,Y) which fails due to uniqueness (Y already exists).
I think: before creating a new one (X,Y), you should .filter(email=user.email) to see whether that e-mail (*,Y) already exists.
Just before the code I posted there's another piece of code that needs the same change.
The text was updated successfully, but these errors were encountered: