fix(policies): tolerate unknown policy type/state in list mapper#18117
Open
max-datahub wants to merge 1 commit into
Open
fix(policies): tolerate unknown policy type/state in list mapper#18117max-datahub wants to merge 1 commit into
max-datahub wants to merge 1 commit into
Conversation
DataHubPolicyInfo.type and .state are free-form strings, so a policy created via ingestion or the API can hold a value outside the GraphQL PolicyType/PolicyState enums. The unguarded Enum.valueOf in PolicyInfoPolicyMapper threw IllegalArgumentException, which failed the entire listPolicies request for any page that contained such a policy (surfaced in the UI as "Failed to load policies! An unexpected error occurred." — the first page loads fine while later pages error). Fall back to a safe default (type -> METADATA, state -> INACTIVE) and log a warning, so one malformed policy no longer breaks the whole page. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PolicyInfoPolicyMapperconverts a policy's storedtypeandstateto the GraphQLPolicyType/PolicyStateenums with an unguardedEnum.valueOf:DataHubPolicyInfo.typeand.stateare free-formstringfields in the metadata model, so a policy created via ingestion or the API can hold a value that is not a member of the GraphQL enum. In that casevalueOfthrowsIllegalArgumentException, which is unhandled and fails the entirelistPoliciesrequest for any page that contains such a policy.In the UI (Settings → Permissions → Policies) this appears as "Failed to load policies! An unexpected error occurred." — the first page of default/bootstrap policies loads fine, but later pages that contain the offending policy error out and render empty.
Fix
Fall back to a safe default and log a warning instead of throwing, so one malformed policy no longer takes down the whole page (and the policy stays visible/manageable so an admin can correct or delete it):
type→METADATAstate→INACTIVEThis only affects the GraphQL read/mapping path; policy authorization enforcement reads
DataHubPolicyInfodirectly and is unaffected.Testing
New
PolicyInfoPolicyMapperTest(written test-first): valid values map unchanged; an unknowntype/stateno longer throws and falls back to the default. 3 passing.Checklist
🤖 Generated with Claude Code