[PR #812] [MERGED] Fixes #635 - Unique constraint violation when using U2F tokens on PostgreSQL #2806

Closed
opened 2026-03-03 08:53:09 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/dani-garcia/vaultwarden/pull/812
Author: @swedishborgie
Created: 1/14/2020
Status: Merged
Merged: 1/16/2020
Merged by: @dani-garcia

Base: masterHead: postgresql


📝 Commits (2)

  • 76743ae Fixes #635 - Unique constraint violation when using U2F tokens on PostgreSQL
  • e196ba6 Switch error handling to ? operator instead of explicit handling.

📊 Changes

1 file changed (+7 additions, -0 deletions)

View changed files

📝 src/db/models/two_factor.rs (+7 -0)

📄 Description

Because of differences in how .on_conflict() works compared to .replace_into() the PostgreSQL backend wasn't correctly ensuring the unique constraint on user_uuid and atype wasn't getting violated.

This change simply issues a DELETE on the unique constraint prior to the insert to ensure uniqueness. PostgreSQL does not support multiple constraints in ON CONFLICT clauses.

Please let me know if you'd like to see any changes.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/dani-garcia/vaultwarden/pull/812 **Author:** [@swedishborgie](https://github.com/swedishborgie) **Created:** 1/14/2020 **Status:** ✅ Merged **Merged:** 1/16/2020 **Merged by:** [@dani-garcia](https://github.com/dani-garcia) **Base:** `master` ← **Head:** `postgresql` --- ### 📝 Commits (2) - [`76743ae`](https://github.com/dani-garcia/vaultwarden/commit/76743aee48263f459ad4c8f3fc6a77bd2e482f35) Fixes #635 - Unique constraint violation when using U2F tokens on PostgreSQL - [`e196ba6`](https://github.com/dani-garcia/vaultwarden/commit/e196ba6e869793a37f0f5fa79f0f46c12ec3b40a) Switch error handling to ? operator instead of explicit handling. ### 📊 Changes **1 file changed** (+7 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/db/models/two_factor.rs` (+7 -0) </details> ### 📄 Description Because of differences in how .on_conflict() works compared to .replace_into() the PostgreSQL backend wasn't correctly ensuring the unique constraint on user_uuid and atype wasn't getting violated. This change simply issues a DELETE on the unique constraint prior to the insert to ensure uniqueness. PostgreSQL does not support multiple constraints in ON CONFLICT clauses. Please let me know if you'd like to see any changes. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 08:53:09 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vaultwarden#2806
No description provided.