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

Too many values to unpack #112

Open
xoxys opened this issue Oct 14, 2019 · 4 comments
Open

Too many values to unpack #112

xoxys opened this issue Oct 14, 2019 · 4 comments
Assignees

Comments

@xoxys
Copy link

xoxys commented Oct 14, 2019

Hi,

I try to merge some nested dicts like this:

... 'minio_prefix': {'value': {'minio_prefix': 'aaa'}} ... with ... ''minio_prefix': {'value': ['_unset_']} ... but get an exception:

Traceback (most recent call last):
  File "/home/org/user/Devel/private/python/ansible-doctor/env/bin/ansible-doctor", line 11, in <module>
    load_entry_point('ansible-doctor', 'console_scripts', 'ansible-doctor')()
  File "/home/org/user/Devel/private/python/ansible-doctor/ansibledoctor/__main__.py", line 8, in main
    AnsibleDoctor()
  File "/home/org/user/Devel/private/python/ansible-doctor/ansibledoctor/Cli.py", line 25, in __init__
    doc_parser = Parser()
  File "/home/org/user/Devel/private/python/ansible-doctor/ansibledoctor/DocumentationParser.py", line 30, in __init__
    self._populate_doc_data()
  File "/home/org/user/Devel/private/python/ansible-doctor/ansibledoctor/DocumentationParser.py", line 82, in _populate_doc_data
    anyconfig.merge(self._data, tags, ac_merge=anyconfig.MS_DICTS)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 294, in merge
    _update_fn(self, other, key, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 234, in _update_with_merge
    merge(self[key], val, merge_lists=merge_lists, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 294, in merge
    _update_fn(self, other, key, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 234, in _update_with_merge
    merge(self[key], val, merge_lists=merge_lists, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 294, in merge
    _update_fn(self, other, key, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 234, in _update_with_merge
    merge(self[key], val, merge_lists=merge_lists, **options)
  File "/home/org/user/Devel/private/python/ansible-doctor/env/lib64/python3.7/site-packages/anyconfig/dicts.py", line 300, in merge
    raise type(exc)("%s other=%r" % (str(exc), other))
ValueError: too many values to unpack (expected 2) other=['_unset_']

Any suggestions how to work around it? If there is a type conflict like in this case (value: dict should be merged with value: list) I would expect a fallback to simply override it.

@ssato
Copy link
Owner

ssato commented Oct 15, 2019

Thanks your report!

If there is a type conflict like in this case (value: dict should be merged with value: list)
I would expect a fallback to simply override it.

As you know, there is no good default to merge a string with a list.
Also type conflicts may indicate that given data are somehow invalid.
So I don't want anyconfig behaving smart as you suggested and
just let users decide what should be done for such cases.

In your case, I think it would be better if the later one is like
... ''minio_prefix': {'value': '']} ... or ... ''minio_prefix': {'value': 'unset'}....
(The identity element of monoid string is '' (empty string), I guess.)

@xoxys
Copy link
Author

xoxys commented Oct 15, 2019

Thanks for your feedback. In this case it is not possible to refactor the later one because it is parsed from user input. But you are right, if the in put is malformed I should through an exception instead of some magic :)

@ssato
Copy link
Owner

ssato commented Oct 16, 2019

Although I still believe anyconfig should not behave too 'smart' and hide any some unexpected cases it should not process originally, I changed my mind and think that it might be useful if the following merge strategies are available in anyconfig:

  • MS_REPLACE_ON_CONFLICTS: Replace with the item of the later one if there is conflict (type mismatch for example) found. It's exactly same as your case, I guess. This merge strategy should be needed for cases that given original data is invalid, malformed and difficult or impossible to fix but users want to do so with replacements.
  • MS_NO_REPLACE_ON_CONFLICTS: Do NOT replace and keep the item of the former one if there is conflict found.

How do you think about this? If you like this idea and want, I'll try to implement those merge strategies.

@ssato ssato self-assigned this Oct 16, 2019
@xoxys
Copy link
Author

xoxys commented Oct 21, 2019

@ssato sorry for the late respons. I guess, having a merge strategy to handle such cases would be cool. How does these two described strategies handles current options for list append and dict merge?

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