Repository navigation
fix(databases): answer a bulk update that breaks a unique index with 409 - #14575
Conversation
A bulk update that gives two documents the same value under a unique index raised a Unique exception the action never caught, so it answered 500 general_unknown. The single-document update and both upserts already answer 409; the bulk update now maps Unique the same way. A bulk update cannot change a document ID, so the parent Duplicate is left unmapped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No issues found — approved ✅. This PR teaches the bulk document update endpoint to surface unique-index violations as the proper 409 conflict error and locks that behavior in with an end-to-end test.
Reviewed commit: 9c62907 |
🟢 Tier S · Ready to merge
Bulk row and document updates that collide with a unique index now return the API-specific 409 error instead of a 500. End-to-end coverage verifies that conflict and unchanged records, and exercises rejected queries for aggregate overflow, invalid values and spatial inputs, malformed WKT, regexes, and cursor ordering. Latest changes: The newest commits expand RejectedValues coverage with aggregate-overflow and query-validation cases, and relocate the existing bulk-unique regression test to the end of the trait.
📂 Walkthrough · 2
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
# Conflicts: # tests/e2e/Services/Databases/Queries/RejectedValues.php
What
PATCH /v1/tablesdb/{databaseId}/tables/{tableId}/rows(and the legacyPATCH .../collections/{collectionId}/documents) with data that gives two rows the same value under a unique index answered 500general_unknown. The single-row update and both upserts already answer 409.Staging QA repro:
{"data":{"name":"same"},"queries":[equal grp "uq"]}wherenamehas a unique index.Why
Documents/Bulk/Update.phpnever caughtUtopia\Database\Exception\Unique, whichupdateDocumentsthrows on a unique-index violation. It now maps it torow_unique_constraint_violation/document_unique_constraint_violation(409), the same asDocuments/Update.phpandBulk/Upsert.php. A bulk update can't change a row ID (removeReadonlyAttributesstrips$id), so the parentDuplicate(ID conflict) isn't reachable and isn't mapped.Test
RejectedValues::testBulkUpdateIntoAUniqueIndexIsAConflictcreates a unique index, two rows, and bulk-updates both to the same value. It asserts 409, the unique-constraint type, and that neither row changed. It runs for TablesDB and the legacy Databases API; DocumentsDB skips it because it has no attributes. The fix is in the HTTP action, so this E2E is the test at the fixing layer.origin/mainTablesDBCustomServerTest::testBulkUpdateIntoAUniqueIndexIsAConflict500 general_unknownrow_unique_constraint_violationLegacyCustomServerTest::testBulkUpdateIntoAUniqueIndexIsAConflict500 general_unknowndocument_unique_constraint_violationNot included
The earlier sibling commit on
qfix-errors("regex/geometry errors from the database engine return 400") is left out on purpose. utopia-php/database 8.3.2 refuses an invalid regex, and the malformed geometry, in the library. I ran that commit'stestInvalidRegexPatternIsRejected(list, bulk update and bulk delete × 4 patterns) againstmain's server code with no engine-error backstop:testInvalidRegexPatternIsRejected, TablesDB on Postgresgeneral_query_invalidThe 8.3.2 bump (separate PR) brings its own regex and WKT rejection E2Es.
🤖 Generated with Claude Code