Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1227 Use void return types for operations without meaningful result document #1468

Merged
merged 2 commits into from
Oct 1, 2024

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 26, 2024

Fix PHPLIB-1227

This introduces major breaking changes that we did not deprecate.

@@ -314,17 +310,13 @@ public function createCollection(string $collectionName, array $options = []): a
* getPrevious() and getEncryptedFields() methods, respectively.
*
* @see CreateCollection::__construct() for supported options
* @return array A tuple containing the command result document from creating the collection and the modified "encryptedFields" option
* @return array The modified "encryptedFields" option
Copy link
Member Author

@GromNaN GromNaN Sep 26, 2024

Choose a reason for hiding this comment

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

Instead of a tuple, we return the 2nd element (the encryptedFields), but the return type is not modified.

@@ -189,6 +196,45 @@ protected function assertCollectionExists(string $collectionName, ?string $datab
}
}

/** @param callable():void $closure */
protected static function commandResult(callable $closure): object
Copy link
Member Author

Choose a reason for hiding this comment

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

Read command result from the events. That allows to keep the assertCommandSucceeded. But it might not be necessary if the operations throw an exception when the command fails.

Copy link
Member

Choose a reason for hiding this comment

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

I concur. There should be no reason to maintain assertCommandSucceeded(), although removing it entirely might leave some tests without assertions (easy fix if so).

Copy link
Member Author

@GromNaN GromNaN Sep 27, 2024

Choose a reason for hiding this comment

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

I removed all that assertions. assertCommandSucceeded is still used when running raw commands.

Comment on lines -115 to -117
* * typeMap (array): Type map for BSON deserialization. This will only be
* used for the returned command result document.
*
Copy link
Member Author

Choose a reason for hiding this comment

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

The typeMap option can be removed since we don't return the command results.

Copy link
Member

Choose a reason for hiding this comment

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

Thinking of your comment below on createDataKeys(), I noted you didn't suggest deprecating the typeMap option in 1.x. I also don't think that's necessary and feel we can just rely on upgrade notes for 2.0.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with not needing a deprecation notice for removing typeMap, as we won't throw an error when the option is present, it just won't do anything.

I would point out however that a typeMap option here is a pretty good indication that the caller intends to use the result, so it could be a way to notify users of the changing return type. Since it doesn't catch all cases, I'm not sure it's warranted though.

Copy link
Member Author

@GromNaN GromNaN Sep 30, 2024

Choose a reason for hiding this comment

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

Rebased on #1473

* @throws DriverRuntimeException for errors creating a data key
*/
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array
Copy link
Member Author

Choose a reason for hiding this comment

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

The function return null, we don't need to have a by-reference parameter to output the data keys. Using the returned value is more common.
This change can be backported to 1.x, with a deprecation message if $encryptedFields parameter is passed.

Copy link
Member

Choose a reason for hiding this comment

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

This change can be backported to 1.x

FWIW, I'm OK skipping that and just communicating this in the upgrade notes. I think it's very unlikely that anyone was actually using this API.

Defer to you, though.

Copy link
Member

Choose a reason for hiding this comment

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

If we consider the operation (and thus the API) internal in 1.x, I agree with not adding a deprecation layer in 1.x.

* @throws DriverRuntimeException for errors creating a data key
*/
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array
Copy link
Member

Choose a reason for hiding this comment

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

This change can be backported to 1.x

FWIW, I'm OK skipping that and just communicating this in the upgrade notes. I think it's very unlikely that anyone was actually using this API.

Defer to you, though.

src/Operation/DropCollection.php Show resolved Hide resolved
Comment on lines -115 to -117
* * typeMap (array): Type map for BSON deserialization. This will only be
* used for the returned command result document.
*
Copy link
Member

Choose a reason for hiding this comment

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

Thinking of your comment below on createDataKeys(), I noted you didn't suggest deprecating the typeMap option in 1.x. I also don't think that's necessary and feel we can just rely on upgrade notes for 2.0.

@@ -189,6 +196,45 @@ protected function assertCollectionExists(string $collectionName, ?string $datab
}
}

/** @param callable():void $closure */
protected static function commandResult(callable $closure): object
Copy link
Member

Choose a reason for hiding this comment

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

I concur. There should be no reason to maintain assertCommandSucceeded(), although removing it entirely might leave some tests without assertions (easy fix if so).

@GromNaN GromNaN force-pushed the PHPLIB-1227 branch 3 times, most recently from 96d6c8a to a901218 Compare September 27, 2024 13:28
@GromNaN GromNaN marked this pull request as ready for review September 27, 2024 13:57
@GromNaN GromNaN requested a review from a team as a code owner September 27, 2024 13:57
@GromNaN GromNaN requested review from alcaeus and jmikola September 27, 2024 13:57
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Left a few comments, and I agree with the list of operations that no longer return a result. I'll defer to @jmikola for the detailed review.

UPGRADE-2.0.md Outdated Show resolved Hide resolved
src/Client.php Show resolved Hide resolved
Comment on lines -115 to -117
* * typeMap (array): Type map for BSON deserialization. This will only be
* used for the returned command result document.
*
Copy link
Member

Choose a reason for hiding this comment

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

I agree with not needing a deprecation notice for removing typeMap, as we won't throw an error when the option is present, it just won't do anything.

I would point out however that a typeMap option here is a pretty good indication that the caller intends to use the result, so it could be a way to notify users of the changing return type. Since it doesn't catch all cases, I'm not sure it's warranted though.

* @throws DriverRuntimeException for errors creating a data key
*/
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey, ?array &$encryptedFields = null): void
public function createDataKeys(ClientEncryption $clientEncryption, string $kmsProvider, ?array $masterKey): array
Copy link
Member

Choose a reason for hiding this comment

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

If we consider the operation (and thus the API) internal in 1.x, I agree with not adding a deprecation layer in 1.x.

@GromNaN
Copy link
Member Author

GromNaN commented Sep 30, 2024

Rebased. Ready for review @jmikola @alcaeus

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Two suggestions (your call). LGTM with whatever you decide.

UPGRADE-2.0.md Outdated Show resolved Hide resolved
@@ -29,9 +33,23 @@ public function testCollMod(): void
['index' => ['keyPattern' => ['lastAccess' => 1], 'expireAfterSeconds' => 1000]],
['typeMap' => ['root' => 'array', 'document' => 'array']],
);
$result = $modifyCollection->execute($this->getPrimaryServer());
$modifyCollection->execute($this->getPrimaryServer());
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure that the return value of collMod is entirely irrelevant, as the server docs include a note about being able to infer whether a value actually changed server-side by inspecting the command result:

If the operation is successful but the hidden value has not changed (specifically, hiding an already hidden index or unhiding an already unhidden index), the command omits the hidden_old and hidden_new fields from the output.

I didn't consider that until seeing this test change.

If you agree, I'd suggest just reverting the changes to ModifyCollection. Otherwise, feel free to leave as-is.

Copy link
Member Author

@GromNaN GromNaN Oct 1, 2024

Choose a reason for hiding this comment

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

I reverted the change on this operation. This was missing from #1473, so nothing to revert on v1.x

@GromNaN GromNaN force-pushed the PHPLIB-1227 branch 2 times, most recently from 72bf1b8 to 9b89a1b Compare October 1, 2024 10:07
@GromNaN GromNaN enabled auto-merge (squash) October 1, 2024 10:11
@GromNaN GromNaN merged commit f4962c9 into mongodb:v2.x Oct 1, 2024
28 checks passed
@GromNaN GromNaN deleted the PHPLIB-1227 branch October 1, 2024 11:20
alcaeus added a commit that referenced this pull request Oct 16, 2024
* 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)
alcaeus added a commit that referenced this pull request Oct 29, 2024
* 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)
alcaeus added a commit that referenced this pull request Nov 4, 2024
* 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)
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.

3 participants