cloudformation-cli
cloudformation-cli copied to clipboard
contracts using created_resource have readOnlyProperties stripped
The two code links below are removing readOnlyProperties
from the result of a create. While this describes only having readOnlyProperties
on read/list I think there are times that a create/update should also be able to return readOnlyProperties
. Having them stripped out here causes issues with down stream tests like contract_create_read_success
which will have the readOnlyProperties
in it but the test will fail because we are comparing to the result of the create without the readOnlyProperties
.
https://github.com/aws-cloudformation/cloudformation-cli/blob/6e9fd5ceb99750a395885ad69b7d599153538df0/src/rpdk/core/contract/suite/handler_create.py#L34
https://github.com/aws-cloudformation/cloudformation-cli/blob/6e9fd5ceb99750a395885ad69b7d599153538df0/src/rpdk/core/contract/suite/handler_commons.py#L155
+1 Do we have any updates on this?
+1 do we have any updates on this. Our team is facing the same issue.
It seems as if this check should make a copy of the model before doing these check on input being equal to the output so that the created model (output) can be used in later tests without problem. should be a simple fix. @anshikg is this reasoning correct?
if we change the created resource fixture here: https://github.com/aws-cloudformation/cloudformation-cli/blob/6e9fd5ceb99750a395885ad69b7d599153538df0/src/rpdk/core/contract/suite/handler_create.py#L27-L37
to
test_input_equals_output(resource_client, input_model, copy.deepcopy(model)) # or some equivalent way to copy a dict
then, the readOnlyProperties would be present for tests.
I think this might be because we shallow copy instead of deep copying in test_input_equals_output: https://github.com/aws-cloudformation/cloudformation-cli/blob/6e9fd5ceb99750a395885ad69b7d599153538df0/src/rpdk/core/contract/suite/handler_commons.py#L151-L155
switching to deep_copy should result in less conflicts with nested readOnlyProperties being stripped: https://docs.python.org/3/library/copy.html#module-copy