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

functions: Fix defaults for null objects/tuples #28067

Merged
merged 2 commits into from Mar 15, 2021

Conversation

alisdair
Copy link
Member

When using defaults with a value which contains null objects or tuples, we cannot continue to traverse the value and apply defaults. Instead, when we find an attribute which is null, we return early and stop processing this branch.

Previously this would panic. This behaviour is a little counter-intuitive to me, but I think it's consistent with how defaults work. The alternative I considered was replacing the null value with a copy of the given fallback object/tuple, but that wasn't obviously correct either.

Fixes #28046.

When using defaults with a value which contains null objects or tuples,
we cannot continue to traverse the value and apply defaults. Instead,
when we find an attribute which is null, we return early and stop
processing this branch.
@alisdair alisdair added functions experiment/module_variable_optional_attrs 0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged labels Mar 12, 2021
@alisdair alisdair requested a review from a team March 12, 2021 13:26
@alisdair alisdair self-assigned this Mar 12, 2021
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #28067 (7f97bd4) into main (42c6c5d) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
lang/funcs/defaults.go 84.29% <100.00%> (+0.53%) ⬆️
terraform/evaluate.go 52.89% <0.00%> (+0.41%) ⬆️
internal/providercache/dir.go 73.46% <0.00%> (+6.12%) ⬆️

Copy link
Contributor

@pselle pselle left a comment

Choose a reason for hiding this comment

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

Yay fixing beta bugs!

If no default is specified for a nested optional structural typed
attribute, the defaults function should just pass through its input.
Before this commit the function assumed that the fallback value was
always of the correct type, which would panic.
@alisdair
Copy link
Member Author

In following up with the original reporter I found another related panic, so I pushed a follow-up commit adding a fix and tests for that one.

@alisdair alisdair merged commit 783936f into main Mar 15, 2021
@alisdair alisdair deleted the alisdair/defaults-fix-null-structural-types branch March 15, 2021 12:03
@ghost
Copy link

ghost commented Apr 15, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
0.15-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged functions
Projects
None yet
2 participants