Skip to content

fix: handle missing query operators in transaction state filters - #14324

Merged
HarshMN2345 merged 1 commit into
appwrite:fix-transaction-bulk-updatefrom
SahilArate:fix-14222-transaction-state-filter-operators
Oct 12, 2026
Merged

HarshMN2345 merged 1 commit into
appwrite:fix-transaction-bulk-updatefrom
SahilArate:fix-14222-transaction-state-filter-operators

Conversation

@SahilArate

Copy link
Copy Markdown
Contributor

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 query
operators as "matches every row".

The method had no case for notStartsWith, notEndsWith, notContains,
notBetween, and, or, containsAny and containsAll, and no default
branch. For rows already in the transaction state, a bulkUpdate or
bulkDelete using those operators therefore hit rows the database query
excludes (silent data change for bulkUpdate, a 409 conflict for bulkDelete).

Changes:

  • Added the missing operators, with recursion for and / or
  • equal / notEqual are null-safe: null only equals null
    (previously equal u="" matched a null column through loose in_array)
  • contains also works on string attributes, so notContains is correct
    for strings
  • Operators that cannot be evaluated in memory (search, notSearch,
    regex) now return false instead of matching every row

Question for maintainers: for search / notSearch I return false, so the
row is skipped. Happy to throw instead if you prefer.

Test Plan

  • Reproduced the bug by running the original documentMatchesFilters() from
    main with Query / Document from utopia-php/database 7.4.1:
    notStartsWith, notEndsWith, notContains, notBetween, or and
    equal u="" all matched row A, which the database would exclude.
  • Added tests/unit/Databases/TransactionStateTest.php (70 cases) that calls
    the public applyBulkUpdateToState() and applyBulkDeleteToState() for each
    operator, plus the exact scenario from the issue and controls for the
    operators that already worked. 32 of the cases fail without the fix.
  • Unit tests were run with a lightweight runner, not the full Docker stack;
    relying on CI for the full run.

Related PRs and Issues

Checklist

  • [ ✅] Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

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
@ghost

ghost commented Oct 10, 2026

Copy link
Copy Markdown

🟡 Tier B · Needs changes before merging

The fallback can silently undo a transaction bulk update that uses a valid search filter on a document already in transaction state.

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.

Verdict New comments Fixed Still open
🛑 Changes requested 1 0 0
Finding Where
🟠 Skipping search leaves dependent bulk updates stale src/Appwrite/Databases/TransactionState.php:804
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
File Change
src/Appwrite/Databases/TransactionState.php Adds logical, negative, and contains query evaluation plus a safe fallback for unsupported operators.
tests/unit/Databases/TransactionStateTest.php Covers transaction-state bulk operations across supported, unsupported, and existing filters.

Reviewed 8ac85e6 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Tier B · 1 blocking finding to address. Summary

Comment on lines +804 to +808
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@HarshMN2345
HarshMN2345 changed the base branch from main to fix-transaction-bulk-update October 12, 2026 13:53
@HarshMN2345
HarshMN2345 merged commit c423b5b into appwrite:fix-transaction-bulk-update Oct 12, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Transaction bulkUpdate changes rows that do not match the filter

2 participants