Skip to content

fix(policies): tolerate unknown policy type/state in list mapper#18117

Open
max-datahub wants to merge 1 commit into
masterfrom
fix/policy-list-tolerate-unknown-enum
Open

fix(policies): tolerate unknown policy type/state in list mapper#18117
max-datahub wants to merge 1 commit into
masterfrom
fix/policy-list-tolerate-unknown-enum

Conversation

@max-datahub

Copy link
Copy Markdown
Collaborator

Summary

PolicyInfoPolicyMapper converts a policy's stored type and state to the GraphQL PolicyType / PolicyState enums with an unguarded Enum.valueOf:

result.setType(PolicyType.valueOf(info.getType()));
result.setState(PolicyState.valueOf(info.getState()));

DataHubPolicyInfo.type and .state are free-form string fields 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 case valueOf throws IllegalArgumentException, which is unhandled and fails the entire listPolicies request 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):

  • unknown typeMETADATA
  • unknown stateINACTIVE

This only affects the GraphQL read/mapping path; policy authorization enforcement reads DataHubPolicyInfo directly and is unaffected.

Testing

New PolicyInfoPolicyMapperTest (written test-first): valid values map unchanged; an unknown type/state no longer throws and falls back to the default. 3 passing.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable) — n/a
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable) — n/a
  • For any breaking changes, inform the DataHub team — none

🤖 Generated with Claude Code

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>
@github-actions github-actions Bot added the product PR or Issue related to the DataHub UI/UX label Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@maggiehays maggiehays added the needs-review Label for PRs that need review from a maintainer. label Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Label for PRs that need review from a maintainer. product PR or Issue related to the DataHub UI/UX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants