Skip to content
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

convert: strip optional attributes out of empty maps #198

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

liamcervante
Copy link
Contributor

We had previously fixed this for lists and sets in #135.

There's a thread in that PR that asks why not for maps as well. At the time the issue wasn't being reproduced for maps in the same way because maps perform a post-conversion unification here. This was stripping the optional attributes out in the original test case for maps, explaining why we didn't see this in maps before.

The new test cases uses maps in a way that the unification logic isn't called (by only using empty maps without nesting) and now exposes the same problem.

@apparentlymart, I'm not sure if we also want to add the same unification logic to the other collections as well? But either way, I think stripping the optional attributes out of the map is the right thing to do and I probably should have just done it last time even though there was some unexplained behaviour as to why it wasn't needed.

@apparentlymart
Copy link
Collaborator

Thanks for working on this, @liamcervante!

I didn't ultimately complete all of the future todo items I'd listed out in that other PR, or else calling cty.MapValEmpty with a "target type constraint" like this would've been an immediate panic. I guess that worked out in Terraform's favor in this case!

Overall this makes sense to me, and I'm intending to merge it in a moment.


Regarding the question of why that conversionUnifyCollectionElements call is there: I'm not actually sure, but that extra treatment of maps came from here, which has some good commit message commentary about it: 8a7a7a8.

It does seem like that situation might potentially apply to lists and sets too, but the conversion functions for collection-to-list and collection-to-set are shaped quite differently and so are perhaps handling that situation in a different way. 🤔 I'm not 100% sure there isn't a bug there, but I think I'd prefer to wait until there's actually an example of it failing before trying to address it.

@apparentlymart apparentlymart merged commit 86acbd7 into zclconf:main Jan 2, 2025
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.

2 participants