Skip to content

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

Description

@JoshiJoshiJoshi

👟 Reproduction steps

  1. Table with columns n (integer), ds (varchar), ix (varchar), grp (varchar). Two rows in group g: row A {ix: "keep", n: 1, ds: "orig"}, row B {ix: "other", n: 9, ds: "orig"}.
  2. Create a transaction and stage three operations:
    • update A on an unrelated field (so A enters the transaction state),
    • bulkUpdate with data: {ds: "BULK", n: increment 100} and queries [equal grp=g, notStartsWith ix="ke"] — in the database this matches only B, not A (ix="keep" starts with ke),
    • upsert A (writes A back from the state).
  3. Commit and read A.

👍 Expected behavior

A keeps ds="orig", n=1: the bulkUpdate filter does not match A, so A must not be changed. (With a supported filter like equal ix="other" this is exactly what happens — control case.)

👎 Actual Behavior

A is changed to ds="BULK", n=101, although the database query excludes it. Any query operator that TransactionState::documentMatchesFilters() does not implement makes every row already in the transaction state match, so a bulkUpdate/bulkDelete hits rows it should skip.

Affected operators (each 2 runs, identical): notStartsWith, notEndsWith, notContains, notBetween, or, and equal on a null column (equal u="" matched A whose u is null). Supported operators work correctly (equal, notEqual, startsWith, endsWith, greaterThan, lessThan, between, isNull, isNotNull). notSearch happens to fail the commit with 400 (fulltext required), so it does no damage.

A row is only affected if the transaction already touched it before the bulk operation (created/updated/upserted it, or an earlier bulk matched it); rows not yet in the state are matched correctly against the database (control H701). bulkDelete with an unsupported filter instead triggers a 409 conflict (H702).

Cause: TransactionState::documentMatchesFilters() (TransactionState.php L632–L740) has a switch over the query method with cases only for equal, notEqual, contains, startsWith, endsWith, greaterThan, greaterThanEqual, lessThan, lessThanEqual, isNull, isNotNull, between. For any other method there is no case and no default, so the loop falls through and the function returns true at the end (L739). applyBulkUpdateToState() (L248) then applies the bulk data to those state documents, and handleBulkUpdateOperation() re-writes them (Transactions/Update.php L888–L944). main has the same code. The equal-on-null case differs from SQL because PHP in_array(null, [""]) is loose.

🎲 Appwrite version

2.3.0

💻 Operating system

Linux (Debian 12), Docker

🧱 Your Environment

Self-hosted Appwrite 2.3.0, Postgres adapter (PostgreSQL 18), two API nodes.

💡 Suggested fix

In documentMatchesFilters() add the missing query operators (notStartsWith, notEndsWith, notContains, notBetween, notSearch, search, or, and), use strict comparison for equal/notEqual, and treat any still-unknown method as "not matched" (return false) or raise instead of defaulting to true.

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find a similar issue

🏢 Have you read the Code of Conduct?

  • I have read the Code of Conduct

Activity

  1. added
    product / databases
    product / functions
    on Oct 7, 2026
  2. Prakhar0136 commented on Oct 8, 2026

    @Prakhar0136

    Hi! I would like to work on this issue. I have been looking into the transaction bulk Update behavior and would like to try fixing it if it’s still reproducible. Would it be okay if I take this one?

  3. SahilArate commented on Oct 8, 2026

    @SahilArate
    Contributor

    Hi I’d like to work on this and have started. I reproduced it against current main: documentMatchesFilters() has no default branch and no cases for notStartsWith, notEndsWith, notContains, notBetween, and, or, containsAny and containsAll, so each of them matches every row already in the transaction state.

    My plan is to add those operators (recursing for and/or), make equal/notEqual null-safe, and make unknown operators return false instead of matching everything. I’ll add unit tests through applyBulkUpdateToState() and applyBulkDeleteToState().

    One question: for operators that can’t be evaluated in memory (search, notSearch, regex), would you prefer returning false (row is skipped) or throwing an exception? I’ll go with false unless you tell me otherwise. Could you assign this to me? I’ll open the PR against main

  4. added a commit that references this issue on Oct 12, 2026
    8ac85e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / databasesproduct / functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions