Skip to content

Fix recast_object for dict values of primitive type - #128

Merged
ammokhov merged 1 commit into
aws-cloudformation:masterfrom
zippolyte:hippo/dict_recast
Oct 22, 2020
Merged

ammokhov merged 1 commit into
aws-cloudformation:masterfrom
zippolyte:hippo/dict_recast

Conversation

@zippolyte

@zippolyte zippolyte commented Oct 22, 2020 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

Handle the case when the values of a dict type are predetermined in the schema, and are a primitive type.
For instance a property definition like this:

        "APrimitiveTypeDict": {
            "type": "object",
            "patternProperties": {
                ".*": {
                    "type": "boolean"
                }
            }
        }

This generates an attribute like I added in the test: Optional[MutableMapping[str, bool]]

Without this fix, the following exception gets raised:

Traceback (most recent call last):
  File "/var/task/cloudformation_cli_python_lib/resource.py", line 104, in _parse_test_request
    ).to_modelled(self._model_cls)
  File "/var/task/cloudformation_cli_python_lib/utils.py", line 127, in to_modelled
    desiredResourceState=model_cls._deserialize(self.desiredResourceState),
  File "/var/task/datadog_integrations_aws/models.py", line 64, in _deserialize
    recast_object(cls, json_data, dataclasses)
  File "/var/task/cloudformation_cli_python_lib/recast.py", line 22, in recast_object
    recast_object(child_cls, v, classes)
  File "/var/task/cloudformation_cli_python_lib/recast.py", line 28, in recast_object
    if "__dataclass_fields__" in dir(cls):
AttributeError: type object 'bool' has no attribute '__dataclass_fields__'

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@zippolyte zippolyte changed the title Fix recast_object for dict values Fix recast_object for dict values of primitive type Oct 22, 2020
@ammokhov

Copy link
Copy Markdown
Contributor

@zippolyte thanks for the contribution, we will review it shortly

@jaymccon jaymccon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ammokhov
ammokhov merged commit 429d335 into aws-cloudformation:master Oct 22, 2020
@zippolyte
zippolyte deleted the hippo/dict_recast branch October 23, 2020 08:18
@zippolyte

Copy link
Copy Markdown
Contributor Author

Thanks for the prompt review ! Any timeline on when a next release will be made ?

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.

4 participants