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

fixed error when a boolean field set to false #4004

Merged
merged 1 commit into from
Oct 1, 2020

Conversation

edwardmedia
Copy link
Contributor

@edwardmedia edwardmedia commented Sep 22, 2020

Fixes hashicorp/terraform-provider-google#7097

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform, and ran make test and make lint to ensure it passes unit and linter tests.
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Ran relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

datacatalog: fixed an error in `google_data_catalog_tag` when trying to set boolean field to `false`

@google-cla google-cla bot added the cla: yes label Sep 22, 2020
@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review.

Thanks for your contribution! A human will be with you soon.

@c2thorn, please review this PR or find an appropriate assignee.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 129 insertions(+), 1 deletion(-))
Terraform Beta: Diff ( 2 files changed, 129 insertions(+), 1 deletion(-))
TF Conversion: Diff ( 1 file changed, 21 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=147951"

Copy link
Contributor

@nat-henderson nat-henderson left a comment

Choose a reason for hiding this comment

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

Is this approach extensible to the false values for other types? double_value = 0, string_value = "", etc? Or is the bool_value the only one we need this for?

@edwardmedia
Copy link
Contributor Author

edwardmedia commented Sep 22, 2020

This is only for bool_value. The root cause is isEmptyValue() can't be used for Boolean to distinguish between real false and empty value as Boolean does not have a 3rd value. I see other types are used in the tests

@nat-henderson
Copy link
Contributor

Right - but won't we also have this problem with the other types?

fields := obj["fields"].(map[string]interface{})
for _, elements := range fields {
values := elements.(map[string]interface{})
if len(values) > 1 {
Copy link
Member

Choose a reason for hiding this comment

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

This seems to remove user-set boolValues, and even ones that are set to True? Even though we are enacting the API's rules, we should either validate during plan or let the user's bad configuration return an error, not change their values underneath the hood.

I think this encoder solves the problem of sending too many boolValue's, but checking if the user has set the field using d.GetOkExists() would do better here to make sure we are carrying out the user's intent. We can check if the value is set, and if not, delete it. How does that sound?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.

Copy link
Member

Choose a reason for hiding this comment

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

Actually backtracking on this: we can't use d.GetOkExists() because fields is a set and cannot be indexed. Don't really know any other way of tell the difference between user set/unset. Do you @ndmckinley ?

We stick with this original approach and only remove if the bool_value is false? Seems slightly better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing sticks out to me. Maybe we should pause this for a day or two and think on it, let it percolate, bring it up in the next Monday meeting if we haven't thought of anything clever by then. What do you think?

Copy link
Contributor Author

@edwardmedia edwardmedia Sep 23, 2020

Choose a reason for hiding this comment

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

good to me

Copy link
Member

Choose a reason for hiding this comment

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

Does the API only except 1 value for fields ? If so we can use One-of validation to make sure the user isn't setting multiple values. Then we are free to delete the extra boolean values in this encoder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the API only take 1 value for each fields. But there is no way to distinguish between empty and false for bool, along with other value types.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 130 insertions(+), 1 deletion(-))
Terraform Beta: Diff ( 2 files changed, 130 insertions(+), 1 deletion(-))
TF Conversion: Diff ( 1 file changed, 22 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=149810"

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 130 insertions(+), 1 deletion(-))
Terraform Beta: Diff ( 2 files changed, 130 insertions(+), 1 deletion(-))
TF Conversion: Diff ( 1 file changed, 22 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=149814"

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 129 insertions(+), 1 deletion(-))
Terraform Beta: Diff ( 2 files changed, 129 insertions(+), 1 deletion(-))
TF Conversion: Diff ( 1 file changed, 21 insertions(+), 1 deletion(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests based on this PR's diffs. See the results here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=149823"

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccProviderMeta_setModuleName|TestAccComputeSnapshot_encryptionCMEK|TestAccContainerCluster_withSandboxConfig|TestAccContainerNodePool_withSandboxConfig|TestAccMonitoringDashboard_basic|TestAccMonitoringDashboard_gridLayout|TestAccMonitoringDashboard_rowLayout|TestAccMonitoringDashboard_update You can view the result here: "https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=149825"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error when trying to set boolean field to false on google_data_catalog_tag
4 participants