A concurrent duplicate write on a relational engine answers 409, not 500 #319

Merged
claude merged 1 commit from feature/311-relational-unique-conflict into develop 2026-11-05 15:59:34 -05:00
Owner

A write that breaks a unique index on SQLite, PostgreSQL, MySQL or SQL Server now answers 409 instead of 500, as MongoDB does since #60. Two concurrent writes both pass a controller's duplicate pre-check; the second used to fail inside SaveChanges with an unmapped DbUpdateException.

  • EntityFrameworkUnitOfWork.SaveChangesAsync catches a DbUpdateException whose inner driver exception is a unique or primary-key violation (UniqueConstraintViolation.IsUniqueViolation): SQLite 19 with extended 2067/1555, PostgreSQL SQLSTATE 23505, MySQL (MySqlConnector) 1062, SQL Server 2601/2627. It logs the driver error at Warning ("A write was rejected by a unique index: …", naming the constraint where the driver gives it) and throws ConflictException, which the controllers answer as 409. Every other DbUpdateException is rethrown unchanged.
  • The core EF project already references the four provider packages, so no new references.
  • Every EF write goes through IUnitOfWork; no code catches DbUpdateException, so no handled path changes. Bulk Execute*/raw SQL statements do not insert and cannot hit a unique violation.
  • The DHCP custom option controller comments describe the 409 on every engine.

Tests (UniqueConflictTestsBase, one subclass per engine, Docker ones carry RequiresDocker): a second insert of the same option tag on one scope that bypasses the pre-check throws ConflictException and logs a Warning (red on develop on all four engines); a foreign-key violation still throws DbUpdateException on all four. Integration.Tests with Docker 515 passed; Web.Tests 2122 (without Docker); Cluster 40 and ClusterSync 47; build 0 warnings; csharpier clean.

Closes #311

🤖 Generated with Claude Code

https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK

A write that breaks a unique index on SQLite, PostgreSQL, MySQL or SQL Server now answers 409 instead of 500, as MongoDB does since #60. Two concurrent writes both pass a controller's duplicate pre-check; the second used to fail inside SaveChanges with an unmapped `DbUpdateException`. - `EntityFrameworkUnitOfWork.SaveChangesAsync` catches a `DbUpdateException` whose inner driver exception is a unique or primary-key violation (`UniqueConstraintViolation.IsUniqueViolation`): SQLite 19 with extended 2067/1555, PostgreSQL SQLSTATE 23505, MySQL (MySqlConnector) 1062, SQL Server 2601/2627. It logs the driver error at Warning ("A write was rejected by a unique index: …", naming the constraint where the driver gives it) and throws `ConflictException`, which the controllers answer as 409. Every other `DbUpdateException` is rethrown unchanged. - The core EF project already references the four provider packages, so no new references. - Every EF write goes through `IUnitOfWork`; no code catches `DbUpdateException`, so no handled path changes. Bulk `Execute*`/raw SQL statements do not insert and cannot hit a unique violation. - The DHCP custom option controller comments describe the 409 on every engine. Tests (`UniqueConflictTestsBase`, one subclass per engine, Docker ones carry `RequiresDocker`): a second insert of the same option tag on one scope that bypasses the pre-check throws `ConflictException` and logs a Warning (red on develop on all four engines); a foreign-key violation still throws `DbUpdateException` on all four. Integration.Tests with Docker 515 passed; Web.Tests 2122 (without Docker); Cluster 40 and ClusterSync 47; build 0 warnings; csharpier clean. Closes #311 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
A concurrent duplicate write on a relational engine answers 409, not 500
Some checks failed
Build / Pack and Push NuGet Packages (dns-core) (push) Successful in -1m52s
Build / Pack and Push NuGet Packages (dns-server) (push) Successful in 1m35s
Build / Build Binary (linux-amd64) (push) Successful in -51s
Build / Build Binary (macos-arm64) (push) Successful in -12s
Build / Build Binary (windows-amd64) (push) Successful in -30s
Build / Test .NET (pull_request) Failing after 10m18s
Build / Pack and Push NuGet Packages (common) (pull_request) Has been skipped
Build / Stage Draft Release (pull_request) Has been skipped
Build / Pack and Push NuGet Packages (dns-core) (pull_request) Has been skipped
Build / Pack and Push NuGet Packages (dhcp) (pull_request) Has been skipped
Build / Build Binary (linux-amd64) (pull_request) Has been skipped
Build / Pack and Push NuGet Packages (dns-server) (pull_request) Has been skipped
Build / Build Binary (linux-arm64) (pull_request) Has been skipped
Build / Build Binary (macos-amd64) (pull_request) Has been skipped
Build / Build Binary (macos-arm64) (pull_request) Has been skipped
Build / Build Binary (windows-amd64) (pull_request) Has been skipped
Build / Smoke Test the Windows Binary (pull_request) Has been skipped
Build / Build Arch Linux Packages (pull_request) Has been skipped
Build / Build and Test Deb and RPM Packages (pull_request) Has been skipped
Build / Build and Push Image (pull_request) Has been skipped
Build / Publish Release (pull_request) Has been skipped
Build / Pipeline (pull_request) Failing after 0s
Build / Build Binary (macos-amd64) (push) Successful in 4m23s
Build / Build Binary (linux-arm64) (push) Successful in 4m25s
Build / Build and Push Image (push) Successful in -2m35s
Build / Smoke Test the Windows Binary (push) Successful in 17s
Build / Build Arch Linux Packages (push) Successful in -2m22s
Build / Build and Test Deb and RPM Packages (push) Successful in -33s
Build / Publish Release (push) Successful in -2m39s
Build / Pipeline (push) Successful in 0s
ba0591cc33
Closes #311

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T33E3pmQvqkTriyQUMNUTK
claude merged commit 0391dfbf33 into develop 2026-11-05 15:59:34 -05:00
Sign in to join this conversation.
No reviewers
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
lantea-one/ninlil!319
No description provided.