Repository navigation
fix: handle missing query operators in transaction state filters - #14324
Conversation
documentMatchesFilters() had no case for notStartsWith, notEndsWith, notContains, notBetween, and, or, containsAny and containsAll, and no default branch, so these operators matched every row already in the transaction state. Add the missing operators, make equal/notEqual null-safe, and make unknown operators never match. Fixes appwrite#14222 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DS3yiV1YkSdmHF1BVYyzeU
🟡 Tier B · Needs changes before merging
This change adds in-memory evaluation for additional transaction-state query operators, makes equality comparisons null-safe, and defaults unsupported filters to non-matching. It also adds unit coverage for bulk update/delete filter behavior and the reported transaction scenario.
Fix with agent prompt### Issue 1
src/Appwrite/Databases/TransactionState.php:804-808
**Skipping search leaves dependent bulk updates stale**
`search` is a valid database filter, but this fallback skips matching documents already in transaction state. In `Update.php`, `handleBulkUpdateOperation()` still sees those documents as dependent and rewrites them from the unchanged state after the database update, silently undoing the bulk update; this can also leave later transaction operations using stale values. Please avoid treating valid-but-unevaluable filters as non-matches for bulk updates (for example, reject them before applying the operation or keep the state synchronized).
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 2
Reviewed |
| default: | ||
| // Operators that cannot be evaluated in memory (e.g. search, | ||
| // notSearch, regex) must never match, otherwise a bulk operation | ||
| // would modify rows that the database query excludes. | ||
| return false; |
There was a problem hiding this comment.
Skipping search leaves dependent bulk updates stale
search is a valid database filter, but this fallback skips matching documents already in transaction state. In Update.php, handleBulkUpdateOperation() still sees those documents as dependent and rewrites them from the unchanged state after the database update, silently undoing the bulk update; this can also leave later transaction operations using stale values. Please avoid treating valid-but-unevaluable filters as non-matches for bulk updates (for example, reject them before applying the operation or keep the state synchronized).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Databases/TransactionState.php
Line: 804-808
Comment:
**Skipping search leaves dependent bulk updates stale**
`search` is a valid database filter, but this fallback skips matching documents already in transaction state. In `Update.php`, `handleBulkUpdateOperation()` still sees those documents as dependent and rewrites them from the unchanged state after the database update, silently undoing the bulk update; this can also leave later transaction operations using stale values. Please avoid treating valid-but-unevaluable filters as non-matches for bulk updates (for example, reject them before applying the operation or keep the state synchronized).
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟠 Major · bug · Reply if this doesn't apply.
c423b5b
into
appwrite:fix-transaction-bulk-update
documentMatchesFilters() had no case for notStartsWith, notEndsWith, notContains, notBetween, and, or, containsAny and containsAll, and no default branch, so these operators matched every row already in the transaction state. Add the missing operators, make equal/notEqual null-safe, and make unknown operators never match.
Fixes #14222
Claude-Session: https://claude.ai/code/session_01DS3yiV1YkSdmHF1BVYyzeU
What does this PR do?
Fixes
TransactionState::documentMatchesFilters()treating unsupported queryoperators as "matches every row".
The method had no case for
notStartsWith,notEndsWith,notContains,notBetween,and,or,containsAnyandcontainsAll, and nodefaultbranch. For rows already in the transaction state, a
bulkUpdateorbulkDeleteusing those operators therefore hit rows the database queryexcludes (silent data change for
bulkUpdate, a 409 conflict forbulkDelete).Changes:
and/orequal/notEqualare null-safe:nullonly equalsnull(previously
equal u=""matched a null column through loosein_array)containsalso works on string attributes, sonotContainsis correctfor strings
search,notSearch,regex) now returnfalseinstead of matching every rowQuestion for maintainers: for
search/notSearchI returnfalse, so therow is skipped. Happy to throw instead if you prefer.
Test Plan
documentMatchesFilters()frommainwithQuery/Documentfrom utopia-php/database 7.4.1:notStartsWith,notEndsWith,notContains,notBetween,orandequal u=""all matched row A, which the database would exclude.tests/unit/Databases/TransactionStateTest.php(70 cases) that callsthe public
applyBulkUpdateToState()andapplyBulkDeleteToState()for eachoperator, plus the exact scenario from the issue and controls for the
operators that already worked. 32 of the cases fail without the fix.
relying on CI for the full run.
Related PRs and Issues
Checklist