Skip to content

fix(versions): fix duplicate entry for key 'c_p_versions_uniq_idx'#2451

Open
mejo- wants to merge 1 commit into
mainfrom
fix/versions_duplicate_key_entry
Open

fix(versions): fix duplicate entry for key 'c_p_versions_uniq_idx'#2451
mejo- wants to merge 1 commit into
mainfrom
fix/versions_duplicate_key_entry

Conversation

@mejo-

@mejo- mejo- commented Apr 28, 2026

Copy link
Copy Markdown
Member

A race condition in requests could lead to this error as two requests tried to create version entries for the same fileId + timestamp combination.

Fix the bug by catching these errors and handling them gracefully.

Fixes: #1886
Fixes: #2405

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits

@mejo- mejo- self-assigned this Apr 28, 2026
@mejo- mejo- requested a review from max-nextcloud as a code owner April 28, 2026 14:54
@mejo- mejo- added the bug Something isn't working label Apr 28, 2026
@mejo- mejo- requested a review from silverkszlo as a code owner April 28, 2026 14:54
@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity team Apr 28, 2026
@mejo- mejo- moved this from 🧭 Planning evaluation (don't pick) to 👀 In review in 📝 Productivity team Apr 28, 2026
A race condition in requests could lead to this error as two requests
tried to create version entries for the same fileId + timestamp
combination.

Fix the bug by catching these errors and handling them gracefully.

Fixes: #1886
Fixes: #2405

Signed-off-by: Jonas <jonas@freesources.org>
@mejo- mejo- force-pushed the fix/versions_duplicate_key_entry branch from cf12b9c to f6621ec Compare April 28, 2026 22:09
@mejo- mejo- moved this from 👀 In review to 🏗️ In progress in 📝 Productivity team May 28, 2026
Comment on lines +111 to +116
try {
$this->collectiveVersionMapper->insert($versionEntity);
} catch (DBException $e) {
if ($e->getReason() !== DBException::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
throw $e;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have our own exception for this and throw it from the ->insert() function.

That way we could easily catch it without rethrowing other DBExceptions.

@max-nextcloud max-nextcloud left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment. Other that that looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: 🏗️ In progress

Development

Successfully merging this pull request may close these issues.

Unique violation error in oc_collectives_p_versions during Desktop Client synchronization Duplicate entry '...' for key 'c_p_versions_uniq_idx'

2 participants