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

Python 3.8 - Update _check_keys to avoid Runtime Error when sanitizing response for keywords #1562

Open
wants to merge 1 commit into
base: development
Choose a base branch
from

Conversation

oldarmyc
Copy link

@oldarmyc oldarmyc commented Nov 2, 2020

Issues: Runtime error sanitizing python keywords from dictionary
Fixes #1561

Problem: In Python 3.8 a Runtime error is thrown when sanitizing python keywords from response dictionary.

    def _check_keys(self, rdict):
        """Call this from _local_update to validate response keys

            disallowed server-response json keys:
            1. The string-literal '_meta_data'
            2. strings that are not valid Python 2.7 identifiers
            3. strings beginning with '__'.

            :param rdict: from response.json()
            :raises: DeviceProvidesIncompatibleKey
            :returns: checked response rdict
            """
        if '_meta_data' in rdict:
            error_message = "Response contains key '_meta_data' which is "\
                "incompatible with this API!!\n Response json: %r" % rdict
            raise DeviceProvidesIncompatibleKey(error_message)

>       for x in rdict:
E       RuntimeError: dictionary keys changed during iteration

Analysis: Changing the iteration to loop through a copy of the response dictionary and update the original, to avoid updating the dictionary while looping through it.

Tests: The following existing tests within bigip/test/unit/test_resource.py cover the proposed changes.
test_Resource__check_keys_python_keyword
test_Resource__check_for_python_keywords
test_Resource__check_for_python_keywords_recursive

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

Successfully merging this pull request may close these issues.

Python 3.8 - Runtime error sanitizing python keywords from dictionary
1 participant