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 single key/value in Diplomat::Kv.get with convert_to_hash option ON #147

Merged
merged 4 commits into from
Jul 21, 2017

Conversation

cheokman
Copy link
Contributor

fix single key/value in Diplomat::Kv.get with conver_to_hash options ON

@taharah taharah changed the title fix single key/value in Diplomat::Kv.get with conver_to_hash option ON fix single key/value in Diplomat::Kv.get with convert_to_hash option ON Jul 1, 2017
Copy link
Member

@taharah taharah left a comment

Choose a reason for hiding this comment

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

Thanks for catching this! Its definitely a byproduct of the inconsistent return that is happening with single values. I know there is an open issue to change this behavior, but we won't be able to change that behavior without a major version bump. What are your thoughts on just returning the single value in place of just an empty hash? At least then the end user would get the value albeit not in the requested format.

@cheokman
Copy link
Contributor Author

cheokman commented Jul 3, 2017

From user perspective, if I use get API with options convert_to_hash: true, I will expect return is a hash even an empty one when no data.
I think it is the reason why convert_to_hash method will not check data is a hash or not:

# Converts k/v data into ruby hash
# rubocop:disable MethodLength, AbcSize
    def convert_to_hash(data)
      collection = []
      master     = {}
      data.each do |item|

I believe it is a contract between convert_to_hash and return_value, and convert_to_hash method expected the input data always a hash or an empty hash.
Unfortunately, return_value will return inconsist value when convert_to_hash options set to true, and return a string when single item in consul, but not a hash contained one and only one element. The method convert_to_hash raise an exception when loop through data, made whole program crashed.

So, I consider return_value need to respect convert_to_hash option and compatible with other usage when false in convert_to_hash option, and add optional param in return_value to determine when to return hash or string in one element in consul case.

@taharah taharah merged commit 7502e06 into WeAreFarmGeek:master Jul 21, 2017
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