Skip to content

Implemented nested dict re-cast #174

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

Conversation

JohnPreston
Copy link
Contributor

@JohnPreston JohnPreston commented Feb 11, 2022

Related to #172

When trying to recast dict items, if the key is not found, it will iterate over the "nested" dict items first.
At first, I had

    except KeyError:
        child_cls = _field_to_type(cls.__dataclass_fields__[k].type, k, classes)
        for _child, _child_definition in v.items():
            recast_object(child_cls, _child_definition, classes)
            _new_child = child_cls._deserialize(_child_definition)
            json_data[k][_child] = _child_definition

which works fine. However, then the recast_test would not pass as the type for json_data[k][_child] would be that of cls instead of more "primitive" ones.
Drawback to that is that in the handlers code, every object is a dict instead of being of type cls. which means no access to the object attributes directly.

Welcome for suggestions on how to keep the typing in handlers when using model instead of having to deal in pure dict

Edit 1:
For the record, for the purpose of handlers, casting the nested value to the correct class, then use it and return to CFN works totally fine. In my CFN resource type I left the code as follows

    except KeyError:
        child_cls = _field_to_type(cls.__dataclass_fields__[k].type, k, classes)
        for _child, _child_definition in v.items():
            recast_object(child_cls, _child_definition, classes)
            _new_child = child_cls._deserialize(_child_definition)
            json_data[k][_child] = _new_child

And everything works totally fine.

@JohnPreston
Copy link
Contributor Author

I just realized, I never came across any CFN resource that would have patternProperties 🤔
Is that something then that might be best left unmanaged if not even denied ?

@ammokhov
Copy link
Contributor

Thank you for your contribution. CFN open source team will take a look at the pull request and provide an update. There are some resources that use patternProperties - AWS::Batch::SchedulingPolicy, AWS::Synthetics::Canary, AWS::WAFv2::RuleGroup

@JohnPreston
Copy link
Contributor Author

JohnPreston commented Feb 14, 2022

Thank you for your contribution. CFN open source team will take a look at the pull request and provide an update. There are some resources that use patternProperties - AWS::Batch::SchedulingPolicy, AWS::Synthetics::Canary, AWS::WAFv2::RuleGroup

So 3 I didnt use so far! Bummer
Good to know though. Edit: good to see the WAF one is not a string but uses objects defined too.

Do let me know if this passes your tests and requirements :)
Thanks

@JohnPreston
Copy link
Contributor Author

Hey @ammokhov
What's the status on this ? Are you guys working on something holding up the merge ?
Thank you,

Copy link
Contributor

@ammokhov ammokhov left a comment

Choose a reason for hiding this comment

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

this looks good to me but still subject to integ testing

@JohnPreston
Copy link
Contributor Author

Hello @ammokhov
Any update on this ? And on the error I related to in #171 / AWS Case 9598785821
Thank you,

Copy link
Contributor

@darrylabbate darrylabbate left a comment

Choose a reason for hiding this comment

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

I pulled these changes and did some manual integration testing. LGTM.

@darrylabbate
Copy link
Contributor

@JohnPreston

We'll have to add some kind of CLA integration for future PRs, but for now, can you simply respond to this issue with this text to confirm you give us the right to include your contribution to our code base?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

License for reference.

@JohnPreston
Copy link
Contributor Author

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@darrylabbate darrylabbate merged commit 1fee342 into aws-cloudformation:master Mar 22, 2022
@JohnPreston JohnPreston deleted the fix/patternProperties-nested-objects branch March 25, 2022 10:56
kddejong pushed a commit to kddejong/cloudformation-cli-python-plugin that referenced this pull request Oct 13, 2022
kddejong pushed a commit to kddejong/cloudformation-cli-python-plugin that referenced this pull request Oct 13, 2022
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.

5 participants