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

[2/2] #35 Fix infinite plan on user metadata #250

Merged
merged 1 commit into from
Jul 20, 2022

Conversation

sergiught
Copy link
Contributor

@sergiught sergiught commented Jul 18, 2022

Description

Fixes: #35

From: https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id

The metadata fields are an exception to this rule (user_metadata and app_metadata). These properties are merged instead of being replaced but be careful, the merge only occurs on the first level.

The API behaves in an unexpected way for the user_metadata and app_metadata where the values get merged instead of replaced but only on the first level. This means that if we want to completely remove a key from the object we need to send the key with a null value. We try to work around this and give a more predictable behavior for our terraform users by checking if the value was removed and if so, sending it as null so it also gets removed in the API call.

Checklist

Note: Checklist required to be completed before a PR is considered to be reviewable.

Auth0 Code of Conduct

Auth0 General Contribution Guidelines

Changes include test coverage?

  • Yes
  • Not needed

Does the description provide the correct amount of context?

  • Yes, the description provides enough context for the reviewer to understand what these changes accomplish

Have you updated the documentation?

  • Yes, I've updated the appropriate docs
  • Not needed

Is this code ready for production?

  • Yes, all code changes are intentional and no debugging calls are left over

@sergiught sergiught self-assigned this Jul 18, 2022

for key := range oldMap {
if _, ok := newMap[key]; !ok {
newMap[key] = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're applying the following explained logic in alexkappa/terraform-provider-auth0#392 (comment), where in order to properly remove something we need to send it's value as null.

This is because the metadata fields are merged instead of being replaced but the merge only occurs on the first level during a PATCH.

@sergiught sergiught force-pushed the patch/fix-issue35-user-metadata branch from b94b80d to ab53fbc Compare July 18, 2022 18:05
@sergiught sergiught marked this pull request as ready for review July 18, 2022 18:10
@sergiught sergiught requested a review from a team as a code owner July 18, 2022 18:10
@codecov-commenter
Copy link

Codecov Report

Merging #250 (ab53fbc) into patch/fix-issue33-user_metadata (82d87a1) will decrease coverage by 0.02%.
The diff coverage is 78.57%.

@@                         Coverage Diff                         @@
##           patch/fix-issue33-user_metadata     #250      +/-   ##
===================================================================
- Coverage                            83.51%   83.48%   -0.03%     
===================================================================
  Files                                   36       36              
  Lines                                 6835     6859      +24     
===================================================================
+ Hits                                  5708     5726      +18     
- Misses                                 898      902       +4     
- Partials                               229      231       +2     
Impacted Files Coverage Δ
auth0/resource_auth0_user.go 73.75% <78.57%> (+0.13%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 82d87a1...ab53fbc. Read the comment docs.

@sergiught sergiught force-pushed the patch/fix-issue33-user_metadata branch from 82d87a1 to 4de639b Compare July 19, 2022 08:37
@sergiught sergiught marked this pull request as draft July 19, 2022 08:48
@sergiught sergiught force-pushed the patch/fix-issue35-user-metadata branch 3 times, most recently from 6f2b50e to 0723a22 Compare July 19, 2022 10:31
}
`

func TestAccUserCanSerializeEmptyMetadataFields(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're removing this as we added it as a last test case for the TestAccUser scenario.

@sergiught sergiught marked this pull request as ready for review July 19, 2022 10:55
@sergiught sergiught requested a review from willvedd July 19, 2022 10:55
Base automatically changed from patch/fix-issue33-user_metadata to main July 19, 2022 16:19
@sergiught sergiught force-pushed the patch/fix-issue35-user-metadata branch 2 times, most recently from a5b254a to da76ed6 Compare July 20, 2022 15:24
@sergiught sergiught force-pushed the patch/fix-issue35-user-metadata branch from da76ed6 to 8f81eeb Compare July 20, 2022 15:29
@sergiught sergiught merged commit e9d3fb5 into main Jul 20, 2022
@sergiught sergiught deleted the patch/fix-issue35-user-metadata branch July 20, 2022 15:40
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.

Infinite plan: user_metadata
4 participants