-
Notifications
You must be signed in to change notification settings - Fork 43
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
Lists are lost when using Extend #22
Comments
Hi @tiramiseb, Thanks for the report! I will dig into it asap. |
Any news? |
Unfirtunatelly, I have no enough time to dig and solve. Could you raise a PR with the solution? |
because of the code : |
Co-authored-by: Håkon Bårsaune <[email protected]>
Well, you probably did a very bad thing: you made the Extend() function flip config which is getting extended, and the config which does extend. Now all the code where people used this, will stop working. Basically, you broke the lib. |
If you did this, you should have left original version as it was, and create a new additional extend. In previous version, it wasn't quite clear what extends what, but quick look at source code was enough to clarify it. At least it was untuitive. Now you made it reversed, and non-intuitive. Maybe it should be ExtendThe() and ExtendBy(), to avoid ambiguity. And still: breaking the lib API contract, is the very bad move. |
@molproduktooo, hey, thanks for getting back. I haven’t reviewed it properly but breaking API is definitely the thing I would prefer avoiding. Feel free reverting the change that broke the original behaviour with a short explanation, example and new test case. I will be more than happy reviewing it. cc @haakonbaa |
Additionally, to the above. I suspected this when read the description of new Extend, and now after carefully reviewing the code am certain about this. Look at this https://github.com/olebedev/config/blob/7eaf6b4b0aa2/config.go#L432 Basically, you @haakonbaa undermined the very idea of this extend. You broke the very concept, of why it is (was) useful. Do you know what the CSS is? Yeah, that "styles" thing? There's this magic word "cascade". Or, maybe you know something about Prototype-based inheritance? Doesn't it ring a bell? What previous Extend did: added non-existent parts of config, PLUS did overwrite existing with new values. I.e. is was like CSS, you could SPECIALIZE the parent config, more general one, with child config, more specific one. One typical use of it was making two configs, one with general defaults, and one with specific customization values. What current Extend does: it kind of "enriches" the config with missing fields. It's no longer a cascade, no longer an inheritance. I even don't know what the use of it might be. Looks like a diversion. |
Sorry for being toxic. Would add tests, it's just all about time. I didn't added tests for the PR I submitted a year ago #24 In the meantime, I use this fork of mine, https://github.com/rusriver/config, which now has functions to parse time durations, and some other improvements. Maybe it'd be useful @olebedev |
I'm really sorry. I misunderstood the purpose of the function. I should have read and understood the functionality before i redid the whole thing. @olebedev @molproduktooo |
To solve the original issue, as @once168 rightly pointed out, this simple change should be made (if I am correct): function set(), current code with context:
this line should be added:
Can't make a PR at the moment, using some weird account now. This should fix the problem. |
and len() instead of cap() must've been there, also. Normalize slice SIZE, capacity is managed by Go runtime. Currently this may either work, or panic, depending on it's M.O. |
When extending a config with a second Config object which contains lists, all elements in lists in the second object, except the first element, are lost.
I have narrowed it down to the
getKeys
function, which generates values like[foo bar 0]
,[foo bar 1]
,[foo bar 2]
, etc : when removing the wholecase []interface{}:
block in this function, extending seems to work perfectly. I have however not done extensive testing...The text was updated successfully, but these errors were encountered: