Skip to content

chore: generic union transformer and detect zero using reflection#4189

Merged
mergify[bot] merged 10 commits intoaws:mainlinefrom
dannyrandall:chore/strict-union
Nov 18, 2022
Merged

chore: generic union transformer and detect zero using reflection#4189
mergify[bot] merged 10 commits intoaws:mainlinefrom
dannyrandall:chore/strict-union

Conversation

@dannyrandall
Copy link
Copy Markdown
Contributor

@dannyrandall dannyrandall commented Nov 16, 2022

This PR contains three changes:

  1. A generic Union transformer - Union types no longer have to be added individually to the transformers list, as this transformer will handle all cases.
  2. When unmarshalling, Union now uses reflect.IsZero to determine if a value hasn't been set. This means types used in a Union will need to be pointers if the zero value of a type means its been set (e.g., key: false will be considered unset unless the Union type is *bool)
  3. Enables strict unmarshaling of types embedded in Union. This solves an issue where invalid yaml for a struct results in a zero value, requiring most struct types to have their own IsZero function to handle this case. For example, take this struct and unmarshal the below yaml into Union[*string, complex]:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

@dannyrandall dannyrandall requested a review from a team as a code owner November 16, 2022 20:35
@dannyrandall dannyrandall requested review from paragbhingre and removed request for a team November 16, 2022 20:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 16, 2022

🍕 Here are the new binary sizes!

Name New size (kiB) v1.23.0 size (kiB) Delta (%)
macOS (amd) 47676 47548 +0.27
macOS (arm) 47676 48200 ❤️ -1.09
linux (amd) 41932 41812 +0.29
linux (arm) 41932 41220 🥺 +1.73
windows (amd) 38768 38664 +0.27

@dannyrandall dannyrandall marked this pull request as draft November 16, 2022 22:24
@dannyrandall dannyrandall marked this pull request as ready for review November 17, 2022 00:35
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 17, 2022

Codecov Report

Merging #4189 (93366f9) into mainline (b956464) will increase coverage by 0.05%.
The diff coverage is 83.75%.

@@             Coverage Diff              @@
##           mainline    #4189      +/-   ##
============================================
+ Coverage     69.24%   69.29%   +0.05%     
============================================
  Files           250      250              
  Lines         35927    35986      +59     
  Branches        264      264              
============================================
+ Hits          24876    24936      +60     
+ Misses         9856     9853       -3     
- Partials       1195     1197       +2     
Impacted Files Coverage Δ
internal/pkg/manifest/rd_web_svc.go 78.94% <0.00%> (+2.02%) ⬆️
internal/pkg/manifest/union.go 77.77% <76.92%> (-7.94%) ⬇️
...rnal/pkg/deploy/cloudformation/stack/rd_web_svc.go 92.85% <100.00%> (+0.08%) ⬆️
internal/pkg/manifest/transform.go 98.41% <100.00%> (+0.04%) ⬆️
internal/pkg/cli/env_deploy.go 54.31% <0.00%> (-2.99%) ⬇️
internal/pkg/cli/cli.go 16.48% <0.00%> (-1.10%) ⬇️
...al/pkg/deploy/cloudformation/stack/transformers.go 76.86% <0.00%> (-0.33%) ⬇️
internal/pkg/cli/init.go 22.25% <0.00%> (-0.29%) ⬇️
internal/pkg/cli/env_package.go 41.79% <0.00%> (-0.23%) ⬇️
... and 33 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment thread internal/pkg/manifest/transform.go Outdated
Comment thread internal/pkg/manifest/union.go
Comment thread internal/pkg/manifest/union.go Outdated
Comment thread internal/pkg/manifest/union.go Outdated
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

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

Thanks Danny! Let me know what you think of the suggestions!

Comment thread internal/pkg/manifest/transform.go Outdated
Comment thread internal/pkg/manifest/transform.go
Comment thread internal/pkg/manifest/union.go Outdated
Comment thread internal/pkg/manifest/union.go Outdated
efekarakus
efekarakus previously approved these changes Nov 18, 2022
@efekarakus efekarakus added the WIP Pull requests that are being modified now. label Nov 18, 2022
@dannyrandall dannyrandall changed the title chore: generic union transformer and strict union unmarshal chore: generic union transformer and detect zero using reflection Nov 18, 2022
@dannyrandall dannyrandall removed the WIP Pull requests that are being modified now. label Nov 18, 2022
Copy link
Copy Markdown
Contributor

@efekarakus efekarakus left a comment

Choose a reason for hiding this comment

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

looks good to me! Thanks for reverting the changes, I think this looks great.

I just have one suggestion, let me know your thoughts!

Comment thread internal/pkg/manifest/union.go Outdated
@iamhopaul123 iamhopaul123 added the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 18, 2022
@dannyrandall dannyrandall removed the do-not-merge Pull requests that mergify shouldn't merge until the requester allows it. label Nov 18, 2022
@mergify mergify Bot merged commit 6a50bcb into aws:mainline Nov 18, 2022
@dannyrandall dannyrandall deleted the chore/strict-union branch November 18, 2022 22:29
KollaAdithya pushed a commit to KollaAdithya/copilot-cli that referenced this pull request Nov 21, 2022
…s#4189)

This PR contains three changes:
1. A generic `Union` transformer - Union types no longer have to be added individually to the transformers list, as this transformer will handle all cases.
2. When unmarshalling, `Union` now uses `reflect.IsZero` to determine if a value hasn't been set. This means types used in a Union will need to be pointers if the zero value of a type means its been set (e.g., `key: false` will be considered unset unless the Union type is `*bool`)
3. ~Enables strict unmarshaling of types embedded in `Union`. This solves an issue where invalid yaml for a struct results in a zero value, requiring most struct types to have their own `IsZero` function to handle this case. For example, take this struct and unmarshal the below yaml into `Union[*string, complex]`:~

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
mergify Bot pushed a commit that referenced this pull request Nov 22, 2022
Due to changes in #4189, a `*string` is now required to determine if `healthcheck` has been configured using the basic configuration.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
mergify Bot pushed a commit that referenced this pull request Dec 8, 2022
…ice manifest (#4193)

This PR adds `from_environment` under `variables` field.

Should probably get merged only after #4189 so that `Union` type can be used in this PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
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.

6 participants