PHPLIB-1518 WriteResult::get*Count() always return an int on acknowledged result#1454
PHPLIB-1518 WriteResult::get*Count() always return an int on acknowledged result#1454GromNaN merged 3 commits intomongodb:v2.xfrom
WriteResult::get*Count() always return an int on acknowledged result#1454Conversation
WriteResult::get*Count() always return an int on acknowledged result
ef66a68 to
17c183d
Compare
alcaeus
left a comment
There was a problem hiding this comment.
LGTM, but we may want to consider unacknowledged writes in rename.
| // If the update resulted in no modification, it's possible that the | ||
| // file did not exist, in which case we must raise an error. | ||
| if ($updateResult->getMatchedCount() !== 1) { |
There was a problem hiding this comment.
I'm not sure we should consider using unacknowledged writes a valid use case, but in case we do there's a functional change here. If we want to preserve the option to use unacknowledged writes with GridFS, we should check isAcknowledged instead of relying on the null value from getMatchedCount:
| // If the update resulted in no modification, it's possible that the | |
| // file did not exist, in which case we must raise an error. | |
| if ($updateResult->getMatchedCount() !== 1) { | |
| /* If the update resulted in no modification, it's possible that the | |
| * file did not exist, in which case we must raise an error. Checking | |
| * the write result's matched count will be most efficient, but fall | |
| * back to a findOne operation if necessary (i.e. legacy writes). | |
| */ | |
| $found = $updateResult->isAcknowledged() | |
| ? $updateResult->getMatchedCount() === 1 | |
| : $this->collectionWrapper->findFileById($id) !== null; | |
| if (! $found) { |
There was a problem hiding this comment.
In that case, that's a fix to backport to v1.x, as it already throws an exception when there is an unacknowledged operation.
There was a problem hiding this comment.
In that case, let's defer to a separate PR, as this does PR not change existing behaviour.
There was a problem hiding this comment.
let's defer to a separate PR
I assume a ticket needs to be created for this. Please cross-reference it here after doing so.
There was a problem hiding this comment.
I just realized that this second if ($updateResult->getMatchedCount() !== 1) is always true after if ($updateResult->getModifiedCount() === 1) return;.
Do you know what are the "legacy writes" that are mentioned in the comment?
There was a problem hiding this comment.
Legacy opcodes (e.g. OP_UPDATE), which were removed in MongoDB 6.0. At this point, drivers may still use them for unacknowledged writes but all acknowledged writes are guaranteed to use OP_MSG and the corresponding write commands (e.g. update).
01a600d to
4495a6f
Compare
4495a6f to
49fa315
Compare
|
I did not update the UPGRADE file, there is nothing to upgrade. |
* v2.x: PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: Regenerate evergreen configuration (#1503) PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
* v2.x: Add return type hint for Encoder::encode() implementation Reverse pipeline init from an array (#1596) PHPLIB-1617 Accept a Pipeline instance in aggregate and watch methods (#1580) Fix CS Require latest python version (#1564) (#1565) Update src/Operation/Find.php Ignore `disableMD5` option as `md5` field is removed from the spec (#1502) Remove obsolete baseline entries Regenerate evergreen configuration (#1503) PHPLIB-1546 and PHPLIB-1159: Remove CreateCollection flags and autoIndexId options (#1478) PHPLIB-1227 Use void return types for operations without meaningful result document (#1468) Remove deprecated functionality (#1439) PHPLIB-1518 `WriteResult::get*Count()` always return an int on acknowledged result (#1454) PHPLIB-954: Add return types to all methods (#1391) PHPLIB-797: Remove unused methods in UnsupportedException (#1436) Revert "Add final annotations to non-internal Operation classes (#1410)" PHPLIB-953 Make internal classes and Operation classes final (#1392) PHPLIB-1218 Remove deprecated fields from GridFS files (#1398)
Fix PHPLIB-1518
I chose to rely on the driver exception thrown by mongodb/mongo-php-driver#1687