cloudformation-cli icon indicating copy to clipboard operation
cloudformation-cli copied to clipboard

contracts using created_resource have readOnlyProperties stripped

Open kddejong opened this issue 4 years ago • 4 comments

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

kddejong avatar Dec 11 '20 22:12 kddejong

+1 Do we have any updates on this?

shaneyuan18 avatar Dec 19 '20 03:12 shaneyuan18

+1 do we have any updates on this. Our team is facing the same issue.

araphn avatar Jan 15 '21 15:01 araphn

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.

johnttompkins avatar Jan 15 '21 21:01 johnttompkins

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

johnttompkins avatar Feb 23 '21 18:02 johnttompkins