Skip to content

fix(plugin-search): surface shared transaction write failures - #18309

Open
breken-ai wants to merge 1 commit into
payloadcms:mainfrom
breken-ai:fix/plugin-search-transaction-write-errors
Open

breken-ai wants to merge 1 commit into
payloadcms:mainfrom
breken-ai:fix/plugin-search-transaction-write-errors

Conversation

@breken-ai

Copy link
Copy Markdown

What?

Propagate a failed search-index write when the search plugin shares the parent document's MongoDB transaction. Keep the existing onSyncError callback and logging, and make the reindex handler surface the same failure.

Why?

Publishing a document can write its search record with the same req and transaction. If that search write fails, MongoDB rolls back the transaction. Previously syncDocAsSearchIndex logged and swallowed the error, so the publish call could resolve successfully even though its document never persisted. A nested write can also clear req.transactionID, so the fix captures whether the shared transaction existed before attempting the write.

How?

  • Capture the incoming transaction state before the nested search operation.
  • Rethrow search-write errors only when the operation shared that transaction, allowing the parent publish to reject; preserve the existing best-effort behavior for independent search syncs.
  • Propagate that error through the reindex handler instead of swallowing it there.
  • Add unit coverage for create and update failures and a MongoDB integration regression with a unique search field.

Before/after proof: On current main (5448061ac5bbb3d2bd656a329f129596dc1ecdba), the unit tests resolve instead of rejecting, and the MongoDB integration test observes a successful second publish despite its rolled-back document. On this PR commit 198737ab7818996a6acf146b78ae0e3ad57d31cf, the publish rejects and only the first document remains.

Validation: 2 focused unit tests and 21 plugin-search integration tests passed on the pushed commit. ESLint on changed source/integration files reported 0 errors (one config default-export warning), Prettier and git diff --check passed. The plugin declaration build is blocked by unbuilt workspace declarations (TS6305 in Payload/UI), so no full monorepo build is claimed.

Fixes #17699

This branch has not been deployed

No deployments
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: plugin-search silently rolls back the parent publish when a search-doc write fails (swallowed transaction error)

1 participant