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

Review options handling for index creation #1822

Merged

Conversation

deguif
Copy link
Collaborator

@deguif deguif commented Oct 20, 2020

There are multiple changes. Maybe I should split the PR.

  • Better check for options parameters by throwing a TypeError if not an expected type.
  • Ensure $options is always converted to an array (I was planning to add deprecations with \trigger_error('xxx', E_USER_DEPRECATED) for other types in a following PR)
  • Avoid duplicating the delete call when handling boolean or array (now it's unified and treat only the array option, as boolean option filled the array appropriatly).
  • More user friendly messages when option(s) is/are invalid.

@deguif deguif force-pushed the review-options-handling-for-index-creation branch from 4786dfa to c36e254 Compare October 20, 2020 19:09
@ruflin
Copy link
Owner

ruflin commented Oct 21, 2020

I'll probably need a bit more details in the PR description and a changelog ;-)

@deguif deguif force-pushed the review-options-handling-for-index-creation branch from c36e254 to 6b935f4 Compare October 21, 2020 15:27
@deguif
Copy link
Collaborator Author

deguif commented Oct 21, 2020

Just added a better description. I'm adding a changelog.

@deguif deguif force-pushed the review-options-handling-for-index-creation branch from 6b935f4 to 09a22a3 Compare October 21, 2020 16:11
Copy link
Owner

@ruflin ruflin left a comment

Choose a reason for hiding this comment

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

I suggest we get this in as is and follow up with deprecation and more clean up. Does that work for you?

@@ -381,26 +381,31 @@ public function refresh(): Response
*/
public function create(array $args = [], $options = null): Response
Copy link
Owner

Choose a reason for hiding this comment

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

General thought: Should we become more strict on what is allowed to be passed to options? The code below is way too complex as we piled onto it over to time not have a breaking change I guess. Good news is, your PR seems to simplify it at least.

Copy link
Owner

Choose a reason for hiding this comment

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

Update: Just read your PR message again. ++ on deprecation additions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes exactly, I will deprecate all types except array. So this will be backward compatible and will be easy to identify which part to drop when bumping a new major version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By the way there's this PR #1823 that is tied to deprecations, would be nice if you could have a look so that we can go forward and use this mechanism for all futures deprecations. I have several ones in mind ;)

@@ -96,7 +96,9 @@ protected function _createIndex(?string $name = null, bool $delete = true, int $
$client = $this->_getClient();
$index = $client->getIndex($name);

$index->create(['settings' => ['index' => ['number_of_shards' => $shards, 'number_of_replicas' => 1]]], $delete);
$index->create(['settings' => ['index' => ['number_of_shards' => $shards, 'number_of_replicas' => 1]]], [
Copy link
Owner

Choose a reason for hiding this comment

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

Out of curiosity: The old one would still work but we discourage using it like this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes the old one will still work, but it will be deprecated so this is to avoid triggering the future deprecation.

@deguif deguif merged commit ec33b36 into ruflin:master Oct 22, 2020
@deguif deguif deleted the review-options-handling-for-index-creation branch October 22, 2020 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants