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

merge_update() not merging lists #181

Closed
mdione-cloudian opened this issue Nov 5, 2020 · 3 comments
Closed

merge_update() not merging lists #181

mdione-cloudian opened this issue Nov 5, 2020 · 3 comments

Comments

@mdione-cloudian
Copy link

Does this make sense? I need it for myself, but maybe it's not box' responsibility.

13:10 $ ipython3 
Python 3.8.6 (default, Sep 25 2020, 09:36:53) 

In [1]: import box

In [5]: b1 = box.Box({'network-config': [{'use': 'frontend', 'prefix': 24}, {'use': 'backend'}]})

In [6]: b2 = box.Box({'network-config': [{'bogus_key': 'bogus_value'}]})

In [8]: b1.merge_update(b2)

In [9]: b1
Out[9]: <Box: {'network-config': [{'bogus_key': 'bogus_value'}]}>

In [10]: box.__version__
Out[10]: '5.2.0'

I was expecting:

In [9]: b1
Out[9]: <Box: {'network-config': [{'use': 'frontend', 'prefix': 24}, {'use': 'backend'}, {'bogus_key': 'bogus_value'}]}>

or maybe even:

In [9]: b1
Out[9]: <Box: {'network-config': [{'use': 'frontend', 'prefix': 24, 'bogus_key': 'bogus_value'}, {'use': 'backend'}]}>
@cdgriffith
Copy link
Owner

It was not designed that way, but I do think it would be good to include that as a possible option!

@cdgriffith
Copy link
Owner

Looking into to being able to give multiple options for how this happens:

        a = Box()
        a.merge_update({"lister": ["a"]})
        a.merge_update({"lister": ["a", "b", "c"]}, box_merge_lists="extend")
        assert a.lister == ["a", "a", "b", "c"]
        a.merge_update({"lister": ["a", "b", "c"]}, box_merge_lists="unique")
        assert a.lister == ["a", "a", "b", "c"]
        a.merge_update({"lister": ["a", "d", "b", "c"]}, box_merge_lists="unique")
        assert a.lister == ["a", "a", "b", "c", "d"]
        a.merge_update({"key1": {"new": 5}, "Key 2": {"add_key": 6}, "lister": ["a"]})
        assert a.lister == ["a"]

cdgriffith added a commit that referenced this issue Dec 8, 2020
…merge_update` (thanks to Marcos Dione)

* Fixing #177 that emtpy yaml files raised errors instead of returning empty objects (thanks to Tim Schwenke)
* Fixing #171 that `popitems` wasn't first checking if box was frozen (thanks to Varun Madiath)
cdgriffith added a commit that referenced this issue Feb 13, 2021
* Adding support for functions to box_recast (thanks to Jacob Hayes)
* Adding #181 support for extending or adding new items to list during `merge_update`  (thanks to Marcos Dione)
* Fixing maintain stacktrace cause for BoxKeyError and BoxValueError (thanks to Jacob Hayes)
* Fixing #177 that emtpy yaml files raised errors instead of returning empty objects (thanks to Tim Schwenke)
* Fixing #171 that `popitems` wasn't first checking if box was frozen (thanks to Varun Madiath)

Co-authored-by: Jacob Hayes <[email protected]>
@cdgriffith
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants