Skip to content

PHPLIB-1977: Report writeConcernError for aggregate write stages - #2061

Open
GromNaN wants to merge 1 commit into
mongodb:v2.5from
GromNaN:PHPLIB-1977
Open

GromNaN wants to merge 1 commit into
mongodb:v2.5from
GromNaN:PHPLIB-1977

Conversation

@GromNaN

@GromNaN GromNaN commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Fix PHPLIB-1977

Why aggregate: Collection::aggregate() always passes a read preference, so every write-stage aggregate ($out or $merge) went through Server::executeCommand(). libmongoc does not parse writeConcernError on generic commands, so the error was never reported. A primary read preference is now dropped so the command uses Server::executeReadWriteCommand(), which reports it. Other read preferences keep the current path, since the extension has no command method that both honours a read preference and parses writeConcernError.

Specifications: tests/specifications moves to the merged DRIVERS-3684 specification, mongodb/specifications#1998 (mandate the reporting) and mongodb/specifications#2003 (add errmsg to the failpoints). The write-concern-errors suite is enabled, with dropDatabase on a client and dropIndexes on a collection added to the unified test runner. The mapReduce test stays skipped because PHPLIB has no mapReduce API.

Extension: consistent writeConcernError reporting for the other write APIs comes from mongodb/mongo-c-driver#2517 (CDRIVER-6523), included in libmongoc 2.5.8 and shipped by ext-mongodb 2.5.6. That fix only covers cursor-based commands such as mongoc_collection_aggregate, so the library still needs this dispatch change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The narrowly scoped dispatch change has targeted regression coverage and no identified blocking issues.

No open issues 🎉

What changed in this PR

This update corrects aggregate command dispatch in the library, with focused regression coverage for write-stage error reporting.

Changes:

  • Keeps the generic-command fallback for non-primary read preferences.
  • Adds $out and $merge regression cases that assert the reported exception code is 79.
File Description
tests/​UnifiedSpecTests/​UnifiedSpecTest.php Registers the write-concern-error suite with a temporary incomplete marker.
tests/​Operation/​AggregateFunctionalTest.php Tests error reporting for both write stages with an explicit primary read preference.
src/​Operation/​Aggregate.php Removes the primary read preference from execution options to select read-write dispatch.

Review effort: Balanced

@GromNaN
GromNaN changed the base branch from v2.x to v2.5 October 27, 2026 15:23
@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

❌ 17 Tests Failed:

Tests completed Failed Passed Skipped
6181 17 6164 1012
View the full list of 17 ❄️ flaky test(s)
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase10_CanFindAutoEncryptedCaseInsensitiveDocumentBySubstring

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase10_CanFindAutoEncryptedCaseInsensitiveDocumentBySubstring
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase11_CanFindAutoEncryptedDiacriticInsensitiveDocumentBySubstring

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase11_CanFindAutoEncryptedDiacriticInsensitiveDocumentBySubstring
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase1_CanFindADocumentByPrefix with data set "prefix"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase1_CanFindADocumentByPrefix with data set "prefix"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase1_CanFindADocumentByPrefix with data set "prefixPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase1_CanFindADocumentByPrefix with data set "prefixPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase2_CanFindADocumentBySuffix with data set "suffix"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase2_CanFindADocumentBySuffix with data set "suffix"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase2_CanFindADocumentBySuffix with data set "suffixPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase2_CanFindADocumentBySuffix with data set "suffixPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase3_AssertNoDocumentFoundByPrefix with data set "prefix"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase3_AssertNoDocumentFoundByPrefix with data set "prefix"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase3_AssertNoDocumentFoundByPrefix with data set "prefixPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase3_AssertNoDocumentFoundByPrefix with data set "prefixPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase4_AssertNoDocumentFoundBySuffix with data set "suffix"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase4_AssertNoDocumentFoundBySuffix with data set "suffix"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase4_AssertNoDocumentFoundBySuffix with data set "suffixPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase4_AssertNoDocumentFoundBySuffix with data set "suffixPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase5_CanFindADocumentBySubstring with data set "substring"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase5_CanFindADocumentBySubstring with data set "substring"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase5_CanFindADocumentBySubstring with data set "substringPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase5_CanFindADocumentBySubstring with data set "substringPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase6_AssertNoDocumentFoundBySubstring with data set "substring"

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase6_AssertNoDocumentFoundBySubstring with data set "substring"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase6_AssertNoDocumentFoundBySubstring with data set "substringPreview"

Flake rate in main: 20.87% (Passed 906 times, Failed 239 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase6_AssertNoDocumentFoundBySubstring with data set "substringPreview"
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase7_AssertContentionFactorIsRequired

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase7_AssertContentionFactorIsRequired
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase8_CanFindAutoEncryptedCaseInsensitiveDocumentByPrefixAndSuffix

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase8_CanFindAutoEncryptedCaseInsensitiveDocumentByPrefixAndSuffix
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91
MongoDB.Tests.SpecTests.ClientSideEncryption.Prose27_StringExplicitEncryptionTest::testCase9_CanFindAutoEncryptedDiacriticInsensitiveDocumentByPrefixAndSuffix

Flake rate in main: 16.67% (Passed 10 times, Failed 2 times)

Stack Traces | 0s run time
MongoDB\Tests\SpecTests\ClientSideEncryption\Prose27_StringExplicitEncryptionTest::testCase9_CanFindAutoEncryptedDiacriticInsensitiveDocumentByPrefixAndSuffix
MongoDB\Driver\Exception\EncryptionException: Cannot use field 'encryptedText' with 'prefixPreview' queries. 'prefixPreview' is unsupported. Use 'prefix' instead.

.../src/Operation/CreateCollection.php:207
.../src/Operation/CreateEncryptedCollection.php:172
.../src/src/Database.php:301
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:480
.../SpecTests/ClientSideEncryption/Prose27_StringExplicitEncryptionTest.php:91

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment thread src/Operation/Aggregate.php Resolved
@GromNaN
GromNaN force-pushed the PHPLIB-1977 branch 2 times, most recently from 9ef7fc2 to 2feac4d Compare November 3, 2026 20:57
@GromNaN GromNaN added the bug a bug fix label Nov 3, 2026
@GromNaN
GromNaN marked this pull request as ready for review November 3, 2026 21:00
@GromNaN
GromNaN requested a review from a team as a code owner November 3, 2026 21:00
@GromNaN
GromNaN requested review from paulinevos and a balanced review from Copilot November 3, 2026 21:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the aggregate dispatch and write concern error reporting changes.

No open issues 🎉

Review effort: Balanced

Aggregate fell back to Server::executeCommand() whenever a read preference
was set. Collection always sets one, so a writeConcernError returned for a
pipeline ending in $out or $merge was never reported.

A primary read preference is the default for executeReadWriteCommand(), so
drop it and use that method, which reports the error. Other read preferences
still use executeCommand(), because the extension has no command path that
both honours a read preference and parses writeConcernError.

Enable the write-concern-errors spec tests, update tests/specifications to
the merged DRIVERS-3684 specification, and support the dropDatabase and
dropIndexes operations in the unified test runner.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 21:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the aggregate write-error reporting change.

No open issues 🎉

Review effort: Balanced

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

bug a bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants