-
Notifications
You must be signed in to change notification settings - Fork 116
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
Changed Kv.get to always return an array for recursive calls. #51
base: master
Are you sure you want to change the base?
Changed Kv.get to always return an array for recursive calls. #51
Conversation
When executing a recursive Kv.get, and there is only one item to return, Diplomat was returning a string instead of an array of key/value pairs. This means the caller has no idea what the key is for the value returned. To fix the problem, we've added a call to RestClient.return_value that indicates that it whether this is a recurse get. I added a spec to test the above behavoir. One worrisome behavoir remains: if you call Kv.get() with :return and there is no response, I'm not sure what is the proper response. For recursive searches, I pretty sure we're still just returning an empty string. And I think that recursive searches should always return an array.
Thanks @PeterFCaswell agreed! |
@scalp42 Would you do me a favor and do a close review of this code. I don't like to merge my own PR unless someone else takes a look at it. |
@PeterFCaswell I actually think code should always return array of hashes even then no ?recurse was specified. Current code is a hack/substitute for using ?raw api which will return the raw value and can be used for single key only. To me the real problem i'm hitting with diplomat all the time is that Kv.get method is already too much overloaded with all the possible options and while still being too implicitly opinionated about how we want to get the results, thus we have this PR and the one I made with return_nil_values. I'd call for a Kv.get method redesign/simplify, maybe split it into several explicit methods like:
Another thing is to consider dropping pre 1.9.x and lower ruby versions support which will reach it's end of life this January, so that ruby keywords could be used for better readability and usage. |
@piavlo I agree on all those points. |
Yep I also agree. Only thing I'd ask is for there to be a sensible deprecation flow used so that people can migrate over easily, without breaking things for people. On a separate note - are we due a new release of Diplomat? |
I'd say yes to the new release. |
Regarding deprecation how about something ugly but effective as naming new class Diplomat::KV |
I like the idea of not breaking backward compatibility for a certain time (what |
I think we should make the changes on a separate namespace as @piavlo mentioned, add a deprecation message to the old Kv namespace methods, and bump the version up a minor release. When we're ready to remove the old code, we can bump up to a major release and remove the dead code - that should give people who are tracking the latest releases time and fair warning to migrate over to the new syntax. |
I fiddled around quiet a bit with the needed changes here, and this is way more then expected. This patch is not sufficient and will lead to issues if you retrieve single values. I think, before making a new namespace (which makes sense) and changing this, diplomat should completely rethink the way values of trees are gathered,e.g. the current "flattinging" instead of a real hashmap (multi-level), key-base is prefixed to all keys and more. After this, this patch here becomes trivial. Just my 50 cents |
When executing a recursive Kv.get, and there is only one item to
return, Diplomat was returning a string instead of an array of
key/value pairs. This means the caller has no idea what the key
is for the value returned.
To fix the problem, we've added a call to RestClient.return_value
that indicates that it whether this is a recurse get.
I added a spec to test the above behavoir.
One worrisome behavoir remains: if you call Kv.get() with :return
and there is no response, I'm not sure what is the proper response.
For recursive searches, I pretty sure we're still just returning an
empty string. And I think that recursive searches should always
return an array.