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

Additive merge for dict with list values? #11

Open
oerp-odoo opened this issue Nov 22, 2021 · 0 comments
Open

Additive merge for dict with list values? #11

oerp-odoo opened this issue Nov 22, 2021 · 0 comments

Comments

@oerp-odoo
Copy link

I have these dictionaries as a sample:

Y1 = {'migration': {'options': {'install_command': 'odoo2'},
  'versions': [{'version': 'setup',
    'operations': {'pre': ["echo 'pre-operation'"]},
    'addons': {'install': ['crm'], 'upgrade': ['note']}},
   {'version': '0.1.0',
    'operations': {'post': ["echo 'post-operation'"]},
    'addons': {'install': ['web', 'contacts']}}]}}
Y2 = {'migration': {'options': {'install_command': 'odoo'},
  'versions': [{'version': 'setup',
    'operations': {'pre': ["echo 'pre-operation-2'", "echo 'pre-operation'"]},
    'addons': {'install': ['account', 'crm'], 'upgrade': ['note', 'hr']}},
   {'version': '0.1.0',
    'operations': {'post': ["echo 'post-operation'",
      "echo 'post-operation-2'"]},
    'addons': {'install': ['purchase', 'sale']}}]}}
Y3 = {'migration': {'versions': [{'version': '0.2.0',
    'addons': {'install': ['mrp', 'stock']}}]}}

I merge it like this:

from mergedeep import merge, Strategy

d = merge({}, Y1, Y2, Y2, strategy=Strategy.ADDITIVE)
print(d)

And get this output:

{'migration': {'options': {'install_command': 'odoo'}, 'versions': [{'version': 'setup', 'operations': {'pre': ["echo 'pre-operation'"]}, 'addons': {'install': ['crm'], 'upgrade': ['note']}}, {'version': '0.1.0', 'operations': {'post': ["echo 'post-operation'"]}, 'addons': {'install': ['web', 'contacts']}}, {'version': 'setup', 'operations': {'pre': ["echo 'pre-operation-2'", "echo 'pre-operation'"]}, 'addons': {'install': ['account', 'crm'], 'upgrade': ['note', 'hr']}}, {'version': '0.1.0', 'operations': {'post': ["echo 'post-operation'", "echo 'post-operation-2'"]}, 'addons': {'install': ['purchase', 'sale']}}, {'version': 'setup', 'operations': {'pre': ["echo 'pre-operation-2'", "echo 'pre-operation'"]}, 'addons': {'install': ['account', 'crm'], 'upgrade': ['note', 'hr']}}, {'version': '0.1.0', 'operations': {'post': ["echo 'post-operation'", "echo 'post-operation-2'"]}, 'addons': {'install': ['purchase', 'sale']}}]}}

Yet I expect lists to be appended. For example from dicts Y1, Y2, install key in setup version, is ['crm'] and ['account', 'crm'], yet first one is kept values from Y2 is ignored. I expect it to become ['crm, 'account', 'crm']

Is my assumption is incorrect and mergedeep works as intended?

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

No branches or pull requests

1 participant