Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

nested_alter isn't truly recursive #43

Closed
danhje opened this issue Mar 1, 2021 · 4 comments
Closed

nested_alter isn't truly recursive #43

danhje opened this issue Mar 1, 2021 · 4 comments

Comments

@danhje
Copy link
Contributor

danhje commented Mar 1, 2021

nested_alter fails to update elements deep in the hierarchy if the structure of the hierarchy higher up has been altered in the same call. Example:

from nested_lookup import nested_alter

def rename_subkeys(data):
    try:
        data['renamed'] = data.pop('rename me')
    except KeyError:
        pass
    return data


document = {'key': {'rename me': 1}, 'sub': {'key': {'rename me': 1}}}
altered_document = nested_alter(document, 'key', rename_subkeys)
# The above call works, since renaming the first key doesn't alter how the second key is accessed. Result:
# {'key': {'renamed': 1}, 'sub': {'key': {'renamed': 1}}}

document = {'key': {'rename me': {'rename me': 1}}}
altered_document = nested_alter(document, 'key', rename_subkeys)
# This does not work, only one of the keys are renamed. Result: 
# {'key': {'renamed': {'rename me': 1}}}
@danhje
Copy link
Contributor Author

danhje commented Nov 8, 2021

Thanks for merging in my PR! Any plans on doing a release to include this fix?

@russellballestrini
Copy link
Owner

Done, please let me know if it works. Might I ask what project you use nested-lookup in? Looking for Remote help?

@russellballestrini
Copy link
Owner

Please reopen if you have issues!

@danhje
Copy link
Contributor Author

danhje commented Nov 17, 2021

Done, please let me know if it works. Might I ask what project you use nested-lookup in? Looking for Remote help?

Thanks again! Nested-lookup is being used in an internal library which converts pydantic schemas to avro schemas.

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

No branches or pull requests

2 participants