-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Rekey on member #33836
Rekey on member #33836
Conversation
cast_list_to_dict was taking an arbitrary data format in and returning an arbitrary data format out. Rework this to be a more generic function which creates a dict of dicts based on a member of the dict. Remove cast_dict_to_list since rekey_on_member handles the use cases we know about and cast_dict_to_list suffers from the same problems as cast_list_to_dict. If this is still needed we could think about filters we could add to do this in a short jinja2 pipeline.
raise errors.AnsibleFilterError("human_readable() can't interpret following string: %s" % size) | ||
|
||
|
||
def human_to_bytes(size, default_unit=None, isbits=False): | ||
''' Return bytes count from a human readable string ''' | ||
try: | ||
return basic.human_to_bytes(size, default_unit, isbits) | ||
except: | ||
except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e is unsued, just except Exception:
to avoid 'bare exceptions'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
raise errors.AnsibleFilterError(to_native(e)) | ||
|
||
# TODO: We may want to add parameters to allow overwrite or constructing lists instead of erroring | ||
if new_obj.get(key_elem, None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should add an allow_overwrite
or similar param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
ad47558
to
a484732
Compare
Lol, good comments. I have come to understand that ansible core likes what ansible core likes. I do feel at times you have lost understanding of how users use products, but this does cover the main use case so let’s do it!!!! |
Merged to devel for the 2.5.0 release. |
SUMMARY
Objections have been raised to the new filters, cast_list_to_dict() and cast_dict_to_list() which take an arbitrary data structure and transform it into another data structure. Renamed and reworked the filters and code so that the input and output are much less arbitrary.
ISSUE TYPE
COMPONENT NAME
lib/ansible/plugins/filters/mathstuff.py
lib/ansible/plugins/filters/cast_type.py
ANSIBLE VERSION
ADDITIONAL INFORMATION
I was only given one use case. Here's how that one case would compare to the new code as well as how to use the new code in other ways: https://gist.github.com/abadger/af5e5b03b8d8a121f983cc98743062cc