-
Notifications
You must be signed in to change notification settings - Fork 882
Commit 30bcb17
committed
Fix HTTP 422 error in github_organization_settings resource
Fixes #2305
This commit resolves the HTTP 422 error that was occurring when using the
github_organization_settings resource, particularly with Enterprise Managed User (EMU)
organizations.
## Root Cause
The issue was caused by:
1. Unnecessary Organizations.Edit() call with nil parameters
2. Unconditional sending of all fields including empty strings for optional fields
3. Incorrect handling of boolean false values using d.GetOk() instead of d.GetOkExists()
## Changes Made
### Core Fixes
- Replace Organizations.Edit(ctx, org, nil) with Organizations.Get() to safely retrieve organization plan
- Create buildOrganizationSettings helper function that conditionally builds settings struct
- Use d.GetOkExists() for boolean fields to properly handle false values
- Only send explicitly configured fields to avoid API rejections
### Enterprise Support
- Properly handle Enterprise-specific fields like members_can_create_internal_repositories
- Detect enterprise organizations using plan name and conditionally include enterprise fields
### Test Coverage
- Add comprehensive test cases for all parameter types:
* String fields (8 parameters)
* Security boolean fields (6 parameters)
* Repository creation fields (5 parameters)
* Other boolean fields (3 parameters)
* Enum fields (1 parameter)
- Add specific tests for boolean false value handling
- Add tests for complex multi-parameter configurations
- Add tests for enterprise-specific functionality
## Testing
- Manually tested with EMU organization
- Verified all parameter types work correctly
- Confirmed boolean false values are properly sent to API
- Tested complex configurations with multiple field types
- All existing and new tests pass
## Impact
- Resolves HTTP 422 errors for all organization types
- Enables proper management of EMU organization settings
- Maintains backward compatibility
- Improves API payload efficiency by only sending configured fields1 parent f549d17 commit 30bcb17Copy full SHA for 30bcb17
File tree
Expand file treeCollapse file tree
2 files changed
+694
-208
lines changedOpen diff view settings
Filter options
- github
Expand file treeCollapse file tree
2 files changed
+694
-208
lines changedOpen diff view settings
0 commit comments