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

Relax value type in SetProcessor to allow mixed #2082

Merged
merged 1 commit into from
Jun 23, 2022

Conversation

franmomu
Copy link
Contributor

It is defined as string, but in tests there are a couple of places where another type is used:

$processor = new SetProcessor('field1', 582.1);

$set = new SetProcessor('field4', 324);

Looking at the documentation: https://www.elastic.co/guide/en/elasticsearch/reference/7.17/set-processor.html#set-processor looks like any type can be used.

@franmomu franmomu force-pushed the set_processor_value_type branch from 1cfbc61 to adda166 Compare June 21, 2022 14:30
* @return $this
*/
public function setValue(string $value): self
public function setValue($value): self
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's would be a BC break for anyone who reimplemented this method and kept the string $value signature.
But it should be very limited as extending this processor is probably not widespread at all.

Copy link
Owner

Choose a reason for hiding this comment

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

Agree, but I also hope this is very rare. I suggest we mark it as a breaking change in the changelog with a note on when it would be breaking (someone inheriting SetProcessor).

It is one of these scenarios I think where in theory it is a breaking change and I'm pretty sure someone is going to bring up that because of that we (I) don't follow semver but working around it would not bring benefits to the large majority of users. I'm +1 on the change.

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'll update the PR later adding it in the BC Break section, it wasn't intentional, I changed it in the constructor which is not BC break and then changed it in the setValue without thinking about that.

@franmomu franmomu force-pushed the set_processor_value_type branch from adda166 to eb7e4ea Compare June 22, 2022 13:08
@franmomu
Copy link
Contributor Author

There is also another similar issue with Setting::setMergePolicy():

* @param string $key Merge policy key (for ex. expunge_deletes_allowed)
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-merge.html
*/
public function setMergePolicy(string $key, string $value): Response

It expects a string, but in tests:

$settings->setMergePolicy('expunge_deletes_allowed', 15);
$this->assertEquals(15, $settings->getMergePolicy('expunge_deletes_allowed'));
$settings->setMergePolicy('expunge_deletes_allowed', 10);
$this->assertEquals(10, $settings->getMergePolicy('expunge_deletes_allowed'));

and looking at https://github.com/elastic/elasticsearch/blob/56d89577a033c15b518e2d74e55d9605eb90b78a/server/src/main/java/org/elasticsearch/index/MergePolicyConfig.java

seems like it could accept at least int as well.

should we proceed the same way?

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.

Yes, I would say lets do the same.

CHANGELOG.md Outdated
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/ruflin/Elastica/compare/7.1.5...master)
### Backward Compatibility Breaks
* Removed `string` parameter type-hint to `value` in `SetProcessor::setValue`.
Copy link
Owner

Choose a reason for hiding this comment

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

Can you expand this a bit more and explain in which scenarios it is breaking? Basically only if someone inherits from SetProcessor

@ruflin ruflin merged commit 45b46cb into ruflin:master Jun 23, 2022
@franmomu franmomu deleted the set_processor_value_type branch June 23, 2022 12:38
@franmomu franmomu mentioned this pull request Jul 24, 2022
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