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

fix: Replace try() with can(coalesce()) to better handle null values #392

Closed

Conversation

fatmcgav
Copy link

@fatmcgav fatmcgav commented Dec 9, 2024

Description

The default behaviour of try will return a null value if present. So update the logic to use can(coalesce()) which will ignore a null value.

Motivation and Context

Fixes #390

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

…alues

The default behaviour of `try` will return a `null` value if present.
So update the logic to use `can(coalesce())` which will ignore a `null` value.
@@ -92,7 +92,7 @@ resource "aws_lb_listener" "this" {
certificate_arn = try(each.value.certificate_arn, null)

dynamic "default_action" {
for_each = try([each.value.authenticate_cognito], [])
for_each = can(coalesce(each.value.authenticate_cognito)) ? [each.value.authenticate_cognito] : []
Copy link
Member

Choose a reason for hiding this comment

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

this is not a change that we are going to accept. you should change your variables in your wrapper to make it work with the existing implementation. I would start with not using null and instead default to an empty list.

Copy link
Author

Choose a reason for hiding this comment

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

I'm confused though... The change is a safer null-safe implementation with the same end result...

From memory I tried a few different implementations of the object and couldn't find a way of not having the null value come through...
Will setup a reproducer to confirm....

Copy link
Member

Choose a reason for hiding this comment

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

The change is a safer null-safe implementation

I don't know what is meant by this. but in general, you are applying defaults that conflict with the module - therefore, you should adapt your implementation, not the other way around

@bryantbiggs bryantbiggs closed this Dec 9, 2024
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.

"Attempt to get attribute from null value" error
2 participants