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 contains on dict type #5138

Merged
merged 3 commits into from
Jan 31, 2025
Merged

🐛 fix contains on dict type #5138

merged 3 commits into from
Jan 31, 2025

Conversation

arlimus
Copy link
Member

@arlimus arlimus commented Jan 29, 2025

We are experiencing issues where two dict types being compared don't come up with the right results. Here is an example I ran to produce this:

> region = terraform.plan.variables.where( name == "gcp_region" ).first.value;
  terraform.plan.variables.where(name == "service_vpc_connector").all(v: v.value.contains(region) )
[failed] [].all()
  actual:   [
    0: terraform.plan.variable value="projects/prj-acc7/locations/us-central1/connectors/preprod-gen-central1-01" name="service_vpc_connector"
  ]

As you can see above we are looking at the value of the varaible, which clearly is set to the region but doesn't come up. If we print out the variables individually, it all comes out correctly.

The problem is that the string comparison doesn't work when we work with dict types because in that example we have to create code that has to with with arbitrary content and work with filtering on another dict.

This PR fixes the issue.

> region = terraform.plan.variables.where( name == "gcp_region" ).first.value;
  terraform.plan.variables.where(name == "service_vpc_connector").all(v: v.value.contains(region) )
[ok] value: true

CC @scottford-io

We are experiencing issues where two `dict` types being compared don't
come up with the right results. Here is an example I ran to produce
this:

```coffee
> region = terraform.plan.variables.where( name == "gcp_region" ).first.value;
  terraform.plan.variables.where(name == "service_vpc_connector").all(v: v.value.contains(region) )
[failed] [].all()
  actual:   [
    0: terraform.plan.variable value="projects/prj-pp-gen-preprod-net-acc7/locations/us-central1/connectors/preprod-gen-central1-02" name="service_vpc_connector"
  ]
```

As you can see above we are looking at the `value` of the varaible,
which clearly is set to the region but doesn't come up. If we print out
the variables individually, it all comes out correctly.

The problem is that the string comparison doesn't work when we work with
`dict` types because in that example we have to create code that has to
with with arbitrary content and work with filtering on another `dict`.

This PR fixes the issue.

```coffee
> region = terraform.plan.variables.where( name == "gcp_region" ).first.value;
  terraform.plan.variables.where(name == "service_vpc_connector").all(v: v.value.contains(region) )
[ok] value: true
```
Copy link
Contributor

github-actions bot commented Jan 29, 2025

Test Results

3 212 tests  +6   3 208 ✅ +6   1m 52s ⏱️ -14s
  385 suites ±0       4 💤 ±0 
   29 files   ±0       0 ❌ ±0 

Results for commit 961b1af. ± Comparison against base commit ec10d80.

♻️ This comment has been updated with latest results.

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Great improvement @arlimus

@chris-rock chris-rock merged commit dec5f92 into main Jan 31, 2025
17 checks passed
@chris-rock chris-rock deleted the dom/dict-contains branch January 31, 2025 08:38
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants