-
Notifications
You must be signed in to change notification settings - Fork 118
Represent struct fields and map keys; fix ss_default to ignore map keys #4041
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
Conversation
|
Commit: 5204a5c
11 failing tests:
Top 26 slowest tests (at least 2 minutes):
|
fce9d26 to
16e0aa4
Compare
| assert.Equal(t, map[string]any{ | ||
| `tags.env`: "test", | ||
| `tags.team`: "data", | ||
| `tags['env']`: "test", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a case for when the map value is top level? And when the map key is deep nested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added one test for top level map; deep nested is already tested here. In general, structwalk had only a minor update, so don't see a need for additional coverage. Unless you see something that can break?
| return p != nil && p.index == tagDotString | ||
| } | ||
|
|
||
| func (p *PathNode) DotString() (string, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these methods used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, added for completeness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include a test to confirm they work.
| // In any case, this is not a change we should react to. | ||
| // Note, we only consider StringKeys here, because indexes and key-value pairs refer to slices and we want to react to new element in slices. | ||
| // Note, IsStringKey is also too broad - it currently covers struct fields and map keys, we don't want to include map keys here. | ||
| // Note, we only consider struct fields here. Adding/removing elements to/from maps and slices should trigger updates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Maps can have server-side defaults as well. Like tags for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth noting as a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate? How does TF handle those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, sql warehouses have a owner tag by default:
➜ cli-experimental-docker-tf-updated git:(experimental-docker-tf-updated) ✗ databricks warehouses get 0d8458ee2118a58e -p azure-ws | jq .tags
{
"custom_tags": [
{
"key": "Owner",
"value": "eng-dev-ecosystem-team_at_databricks.com"
}
]
}
Looks like Terraform does a suppress diff for these, i.e. ignoring remote changes: https://github.com/databricks/terraform-provider-databricks/blob/f5f476292a7e2198dcf4009d4c0c1411161637f6/sql/resource_sql_endpoint.go#L80
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - good to know. If it's a fixed key we might be able to handle it more precisely than ignoring all custom_tags changes, but ignore custom_tags[key='Owner'] only.
pietern
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
| entry_point: "run" | ||
| environment_key: test_env | ||
| libraries: | ||
| - whl: hello.whl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why the wheel if the test is about tags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason, I just copied job config from another test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed to keep the test tight. Since this is a local only test, the whole tasks block can be omitted.
36ec8c3 to
af2b493
Compare
…e NewDotString/NewBracketString directly in some cases
| } else { | ||
| // Map key with single quotes | ||
| } else if node.index == tagBracketString { | ||
| // Bracket notation: ['field'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice side-effect: formatting is no longer dependent on the node key.
| return p != nil && p.index == tagDotString | ||
| } | ||
|
|
||
| func (p *PathNode) DotString() (string, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to include a test to confirm they work.
| entry_point: "run" | ||
| environment_key: test_env | ||
| libraries: | ||
| - whl: hello.whl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed to keep the test tight. Since this is a local only test, the whole tasks block can be omitted.
|
Commit: 7783e65
47 failing tests:
Top 50 slowest tests (at least 2 minutes):
|
Changes
Why
It was never the intention for map entries to have "server_side_default" feature. (Similar to slice indices in #4038).
Issue appeared when we stopped distinguishing between fields and map keys in struct path #3640
Note, originally the difference between fields and map keys was removed so that
a) users can use either syntax without worrying about matching the type. This is still the case, structaccess still treats those two the same way.
b) "resources.jobs.foo" is printed with dots and not like 'resources.jobs["foo"]'. This is still the case, we don't use structpath's String() for this.
Tests
New regression test.