aws-cloudformation / cloudformation-cli-python-plugin

The CloudFormation Provider Development Toolkit Python Plugin allows you to autogenerate Python code based on an input schema.
Apache License 2.0
108 stars 47 forks source link

Change in type custom resource type handling #89

Closed mikemccabe closed 4 years ago

mikemccabe commented 4 years ago

I recently updated, and my fields in my custom resource stopped working except for 'string'. Maybe I was doing it wrong before?

My schema had a toplevel UserId field of type integer

        "UserId": {
            "type": "integer"
        }

I get the following error running CFN test:

[ERROR] 2020-04-20T06:42:33.702Z        3a99cb01-89c4-1787-deb0-125e4dff798d    Invalid request
Traceback (most recent call last):
  File "/var/task/cloudformation_cli_python_lib/resource.py", line 140, in _parse_test_request
    ).to_modelled(self._model_cls)
  File "/var/task/cloudformation_cli_python_lib/utils.py", line 123, in to_modelled
    desiredResourceState=model_cls._deserialize(self.desiredResourceState),
  File "/var/task/nextdoor_sendgrid_subuser/models.py", line 56, in _deserialize
    recast_object(cls, json_data, dataclasses)
  File "/var/task/cloudformation_cli_python_lib/recast.py", line 29, in recast_object
    raise InvalidRequest(f"Unsupported type: {type(v)} for {k}")
cloudformation_cli_python_lib.exceptions.InvalidRequest: Unsupported type: <class 'int'> for UserId

Switching the schema to string, and casting the (json) UserId with str() when populating the model appears to resolve this. What's going on? We can make do with strings, but it's handy to have types. We ran into the same issue with bools.

ammokhov commented 4 years ago

closing as has been fixed by #94