fix: cloudfront apply crashes with KeyError on metadata#249
Conversation
|
Task linked: DUPLO-41929 CloudFront: All commands failed |
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Review Summary by QodoFix CloudFront apply crash with ID-based create-or-update logic
WalkthroughsDescription• Override apply() method in DuploCloudFront to handle server-assigned distribution IDs • Implement ID-based create-or-update logic instead of name-based lookup • Fix KeyError: 'metadata' crash when applying CloudFront distributions Diagramflowchart LR
A["CloudFront apply request"] --> B{"Body contains Id?"}
B -->|Yes| C["Call update method"]
B -->|No| D["Call create method"]
C --> E["Updated distribution"]
D --> F["Created distribution"]
File Changes1. CHANGELOG.md
|
| Returns: | ||
| resource: The created or updated distribution. | ||
| """ | ||
| if body.get("Id"): |
There was a problem hiding this comment.
This doesn't look right. If I made a yaml file in a repo and then made an action that will "apply" that yaml, then the ID would never be in that file unless you were to update the file after creating it. But then you would not be able to have multiple instances of the same yaml because of that id.
So instead, we need a reliable name_from_body method that uses the comment from the cloudfront body. The comment is the name for a cloudfront, this is actually the case in AWS itself too.
Then the find MUST use the comment or ID to find something. You can review how the tenant.find() method works to understand the flow for a name or id style lookup.
When the find is able to use either a name or id then something using the find can use either the id if given or the name second.
Describe Changes
apply()onDuploCloudFrontsince CloudFront uses server-assigned distribution IDs, not names — the inherited V3apply()callsname_from_body()which expectsbody["metadata"]["name"], causing aKeyErrorId→ update, otherwise → createLink to Issues
https://app.clickup.com/t/8655600/DUPLO-41929
PR Review Checklist