Skip to content

PHPLIB-1057: Deprecate method IndexInfo::isGeoHaystack() #1085

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

Merged
merged 3 commits into from
Jun 13, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 30, 2023

Fix PHPLIB-1057

MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release.

@GromNaN GromNaN requested a review from jmikola May 30, 2023 11:32
@GromNaN GromNaN self-assigned this May 30, 2023
@@ -4,6 +4,9 @@ MongoDB\\Model\\IndexInfo::isGeoHaystack()

.. versionadded:: 1.4

.. deprecated:: 1.16
MongoDB 5.0 and later no longer supports geoHaystack indexes.
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 doc was updated in #1085 (comment) to mention the feature deprecation. I moved this note to a deprecation block.

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.

LGTM with trigger_error (and related test changes) reverted.

Open to discussing this more if my review comment isn't exhaustive enough.

*/
public function isGeoHaystack()
{
trigger_error('MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release', E_USER_DEPRECATED);
Copy link
Member

Choose a reason for hiding this comment

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

I was initially going to point out the phpcs errors below and suggest running phpcbf to add imports for trigger_error and E_USER_DEPRECATED.

Thinking about this some more, I don't think we should actually trigger an error here. So long as the driver may be connected to a pre-5.0 server, it's possible for such an index to exist and there's no reason this method should interrupt the user (especially since it's just an "isser" and not something that would enable them to create such an index).

In the other places where we do this, options are unsupported or deprecated in all of our supported server versions but still stuck in our public API.

If PHPC (via the PHPLIB dependnecy) required a 5.0+ server we could certainly add this but I'm not convinced there's much value in doing so. Instead, I'd suggest a separate JIRA ticket with fixVersion 2.0 to just remind us to back and delete this method from the public API. And consider adding a @todo to the doc block like we have in some other classes:

@todo Remove this in 2.0 (see: PHPLIB-XXXX)

Copy link
Member Author

@GromNaN GromNaN Jun 1, 2023

Choose a reason for hiding this comment

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

The @deprecated annotation should be enough to trigger the cleanup in 2.0

trigger_deprecated is used for autoIndexId option in MongoDB\Operation\CreateCollection. IMO this is the same situation: the lib triggers a deprecation notice for a feature that is supported on old server version only. This is a trigger for developers that they must update their code to upgrade MongoDB server.

if (isset($options['autoIndexId'])) {
trigger_error('The "autoIndexId" option is deprecated and will be removed in a future release', E_USER_DEPRECATED);
}

Starting in MongoDB 4.0, you cannot set the option autoIndexId to false when creating collections in databases other than the local database.

Copy link
Member

Choose a reason for hiding this comment

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

The @deprecated annotation should be enough to trigger the cleanup in 2.0

Makes sense.

trigger_deprecated is used for autoIndexId option in MongoDB\Operation\CreateCollection

autoIndexId is an interesting case, as it looks like it's still perfectly usable with non-replicated collections (i.e. local database). I just dug through the old tickets and it looks like my outstanding question in DRIVERS-473, where I raised concerns about that, was never answered. I just opened PHPLIB-1159 to revisit that discussion.

I propose leaving this PR open until we can discuss PHPLIB-1159 as a team. If we're in agreement that leaving trigger_error() on autoIndexId makes sense, then I won't argue with adding it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We decided to keep the deprecation trigger.

@@ -60,7 +60,9 @@ public function testIsGeoHaystack(): void
$index = $result->current();

$this->assertEquals($indexName, $index->getName());
$this->assertTrue($index->isGeoHaystack());
$this->assertDeprecated(function () use ($index): void {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

@GromNaN GromNaN Jun 1, 2023

Choose a reason for hiding this comment

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

I was happy to find it, otherwise I the tests failed.
Symfony has trigger_deprecation and expectDeprecation for tests: this works with symfony/phpunit-bridge that is already used on this library.

GromNaN added 2 commits June 1, 2023 22:35
MongoDB 5.0 removes support for "geoHaystack" indexes, the method "IndexInfo::isGeoHaystack()" will be removed in a future release
@GromNaN GromNaN merged commit b3607d9 into mongodb:master Jun 13, 2023
@GromNaN GromNaN deleted the PHPLIB-1057 branch June 13, 2023 15:14
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.

2 participants