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

Fix missing hint query option during find #2351

Merged
merged 3 commits into from
Aug 2, 2021
Merged

Fix missing hint query option during find #2351

merged 3 commits into from
Aug 2, 2021

Conversation

TimoBakx
Copy link
Contributor

@TimoBakx TimoBakx commented Aug 2, 2021

Q A
Type bug
BC Break no
Fixes #2346

Summary

This PR fixes the missing hint query option during a find query.

I added two tests: one to make sure the hint gets correctly propagated from the query array to the find method, and one to make sure the hint is correctly carried from the query builder to the query.

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.

Code LGTM, and the PhpStan failure seems unrelated. @franmomu could you please help out here?

@@ -424,7 +424,7 @@ private function runQuery()

switch ($this->query['type']) {
case self::TYPE_FIND:
$queryOptions = $this->getQueryOptions('select', 'sort', 'skip', 'limit', 'readPreference');
$queryOptions = $this->getQueryOptions('select', 'sort', 'skip', 'limit', 'readPreference', 'hint');
Copy link
Member

Choose a reason for hiding this comment

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

For now this fixes the bug, but I'm wondering if we should be more lenient with the options we accept. find take a lot more options than these few, and we may do well to allow people to utilise them. @jmikola any suggestions on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can work out a list of options from the Builder and Collection classes and write a bunch of tests for those in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

Let's hold off on what Jeremy says - not sure we need to test for every single one of them, but I'm rather thinking to just pass everything that we know isn't from ODM on to the driver.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can see, only maxTimeMS and snapshot are still missing. With snapshot being deprecated in the Find class, so I'm not sure if that should be added.

Copy link
Member

Choose a reason for hiding this comment

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

@TimoBakx: I'm not sure what documentation you're referring to, but there are many more options supported by the extension and library:

I think it makes sense for the builder to provide some API to add arbitrary options that may not be explicitly handled in ODM but are known to be supported in the extension/library. However, that would likely require some internal refactoring to the Query class, since many of these fields appear to be stuffed directly into the internal $query property. Handling this might require segregating options into $query['options'] so we no longer need to rely on getQueryOptions to extract specific keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jmikola I looked at all the options that have their own method in the query Builder class (and are added to the $this->query array there and checked which of those were used in the Find class code and were also missing in the $this->getQueryOptions call (which means that the instructions to the Builder would be ignored).

Moving things to separate options would indeed be better, but I'm not sure how much of a BC break that would be. It might be easier to add the missing values first. 🙂

@franmomu
Copy link
Contributor

franmomu commented Aug 2, 2021

I've created #2352 for the phpstan issue

@alcaeus alcaeus added the Bug label Aug 2, 2021
@alcaeus alcaeus added this to the 2.2.2 milestone Aug 2, 2021
@alcaeus alcaeus self-assigned this Aug 2, 2021
@alcaeus alcaeus merged commit 4979c0f into doctrine:2.2.x Aug 2, 2021
@alcaeus
Copy link
Member

alcaeus commented Aug 2, 2021

Thanks @TimoBakx!

@TimoBakx TimoBakx deleted the 2346-find-hint-missing branch August 2, 2021 12:17
alcaeus added a commit that referenced this pull request Aug 5, 2021
* 2.2.x:
  allow to reset hydration setting for Aggregation (#2353)
  Fix missing hint query option during find (#2351)
  Ignore unreachable statement (#2352)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants