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 JSON float formatting #1635

Merged
merged 6 commits into from May 28, 2019

Conversation

@pySilver
Copy link
Contributor

pySilver commented May 27, 2019

See #1634 for details

pySilver added 2 commits May 27, 2019
Preserve zero fraction while JSON serialization
@ruflin

This comment has been minimized.

Copy link
Owner

ruflin commented May 27, 2019

Interesting addition, didn't even know this constant exists. I'm trying to think of any existing deployments we might break with this. In the case someone defined it as integer on the Elasticsearch side already and a float is sent, as far as I know it will just convert it back to integer and keep working. Any ideas on what it could break?

@ezimuel Any thoughts related to this?

@pySilver Could you also add a CHANGELOG entry and some tests to it?

@pySilver

This comment has been minimized.

Copy link
Contributor Author

pySilver commented May 27, 2019

@ruflin I can't see any way it can brake a valid setup here since on both sides data will be in a proper/expected type.

Btw, its a default JSON serialization flag in elasticsearch-php library for a long time already: elastic/elasticsearch-php#481

I'll add changelog entry in a moment, but I'm unable to add tests (I've switched back from python not so long ago and not yet familiar with PHP tests yet)

pySilver added 2 commits May 27, 2019
Adds a note about float serialization
Fix changelog link
@ezimuel

This comment has been minimized.

Copy link
Collaborator

ezimuel commented May 28, 2019

@ruflin, I agree to add JSON_PRESERVE_ZERO_FRACTION for json_encode, we used it in elasticserach-php, as suggested by @pySilver.
I'm not sure about the fix proposed by @pySilver, since the JSON::stringify is also used in other Elastica classes. Instead of change all the stringify calls why don't add JSON_PRESERVE_ZERO_FRACTION directly in JSON::stringify as default parameter?

@ruflin

This comment has been minimized.

Copy link
Owner

ruflin commented May 28, 2019

Wasn't aware we also use it already in the official client. ++ on adding it then :-)

@pySilver WDYT about the proposal from @ezimuel ?

@pySilver

This comment has been minimized.

Copy link
Contributor Author

pySilver commented May 28, 2019

@ruflin I think its totally correct and should be a default behavior for all serialization tasks.

@ruflin

This comment has been minimized.

Copy link
Owner

ruflin commented May 28, 2019

@pySilver Could you modify your PR to this approach?

@pySilver

This comment has been minimized.

Copy link
Contributor Author

pySilver commented May 28, 2019

@ruflin done!

@ruflin

This comment has been minimized.

Copy link
Owner

ruflin commented May 28, 2019

Thanks. Could you try to run make lint. For some reason the linter in CI is happy. The strange thing is the file it complains about is not touched in this PR?!?

@pySilver

This comment has been minimized.

Copy link
Contributor Author

pySilver commented May 28, 2019

@ruflin yeah, same thing on localhost. The reason is here: https://github.com/ruflin/Elastica/blob/master/lib/Elastica/Index/Settings.php#L207 introduced 4m ago at #1569

(Bool should be bool), changing it in my pr.

Antoni Martyniuk
@ruflin
ruflin approved these changes May 28, 2019
@@ -60,6 +60,9 @@ public static function stringify($args/* inherit from json_encode */)
// extract arguments
$args = \func_get_args();
// set defaults
isset($args[1]) ? $args[1] |= JSON_PRESERVE_ZERO_FRACTION : $args[1] = JSON_PRESERVE_ZERO_FRACTION;

This comment has been minimized.

Copy link
@ruflin

ruflin May 28, 2019

Owner

Had to read this line a few times but makes sense now :-)

This comment has been minimized.

Copy link
@pySilver

pySilver May 28, 2019

Author Contributor

Yeah, kinda cryptic. I couldn't find easier way to append const if arg[1] is set/not set.

This comment has been minimized.

Copy link
@chx

chx Oct 2, 2019

$args[1] = ($args[1] ?? 0) | JSON_PRESERVE_ZERO_FRACTION;

This comment has been minimized.

Copy link
@ruflin

ruflin Oct 14, 2019

Owner

Thanks for chiming in @chx . Should we update the code?

This comment has been minimized.

Copy link
@chx

chx Oct 14, 2019

I think so :)

This comment has been minimized.

Copy link
@ruflin

ruflin Oct 16, 2019

Owner

@chx @pySilver Someone wants to take it? ;-)

@ruflin ruflin merged commit 63553e4 into ruflin:master May 28, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@ruflin

This comment has been minimized.

Copy link
Owner

ruflin commented May 28, 2019

@pySilver Thanks for the fix, not sure how that Bool thingy slipped through for so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.