Skip to content

[#12685] fix(core): Fix built-in policy supportedObjectTypes validation and error message - #12686

Merged
mchades merged 6 commits into
apache:mainfrom
paultanay:fix-policy-builtin-object-types-validation
Sep 3, 2026
Merged

[#12685] fix(core): Fix built-in policy supportedObjectTypes validation and error message#12686
mchades merged 6 commits into
apache:mainfrom
paultanay:fix-policy-builtin-object-types-validation

Conversation

@paultanay

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Fix the validation of supportedObjectTypes when updating built-in policies.

PolicyManager.updatePolicyEntity() currently uses Sets.difference(oldTypes, newTypes).isEmpty(), which only detects removed object types. When the updated set contains additional object types, the validation incorrectly passes.

This change:

  • validates that the old and new supported object type sets are exactly equal;
  • fixes the validation error message by supplying the expected and actual sets;
  • adds a regression test covering attempted supported object type changes for a built-in policy.

Why are the changes needed?

Built-in policies must not change their supported metadata object types during an update. The previous asymmetric set comparison did not enforce this invariant for additions.

Fixes #12685

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Code Coverage Report

Overall Project 68.82% +0.99% 🟢
Files changed 85.14% 🟢

Module Coverage
aliyun 19.74% 🔴
api 51.74% -0.13% 🟢
authorization-common 85.96% 🟢
authorization-ranger 4.38% 🔴
aws 53.54% 🟢
azure 32.1% 🔴
catalog-common 19.1% 🔴
catalog-fileset 80.3% 🟢
catalog-glue 69.24% 🟢
catalog-hive 82.96% 🟢
catalog-jdbc-common 45.69% 🟢
catalog-jdbc-doris 82.69% 🟢
catalog-jdbc-mysql 79.33% 🟢
catalog-jdbc-postgresql 83.39% 🟢
catalog-jdbc-starrocks 79.16% 🟢
catalog-kafka 76.99% 🟢
catalog-lakehouse-generic 60.55% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.86% 🟢
catalog-lakehouse-paimon 84.26% 🟢
catalog-model 77.99% 🟢
cli 44.48% 🟢
client-java 77.48% +0.05% 🟢
common 55.43% -1.99% 🟢
core 83.77% +0.88% 🟢
filesystem-hadoop3 76.45% 🟢
flink 0.0% 🔴
flink-common 52.1% 🟢
flink-runtime 0.0% 🔴
gcp 32.2% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 17.84% 🔴
hive-metastore-common 53.4% 🟢
iceberg-aliyun-bundle 0.0% 🔴
iceberg-common 64.75% 🟢
iceberg-rest-server 75.96% 🟢
idp-basic 85.98% 🟢
integration-test-common 0.0% 🔴
jobs 62.92% 🟢
lance-common 32.63% 🔴
lance-rest-server 65.46% 🟢
lineage 53.02% 🟢
optimizer 83.24% 🟢
optimizer-api 21.95% 🔴
server 88.15% +4.87% 🟢
server-common 80.5% 🟢
spark 28.57% 🔴
spark-common 48.92% 🟢
tencent 81.78% 🟢
trino-connector 51.26% 🟢
Files
Module File Coverage
api JobHandle.java 0.0% 🔴
client-java GenericJobHandle.java 100.0% 🟢
common JobDTO.java 89.47% 🟢
AuthMeResponse.java 81.82% 🟢
DTOConverters.java 28.57% 🔴
core GroupMetaBaseSQLProvider.java 100.0% 🟢
JobMetaBaseSQLProvider.java 100.0% 🟢
RoleMetaBaseSQLProvider.java 100.0% 🟢
UserMetaBaseSQLProvider.java 100.0% 🟢
GroupMetaPostgreSQLProvider.java 100.0% 🟢
JobMetaPostgreSQLProvider.java 100.0% 🟢
RoleMetaPostgreSQLProvider.java 100.0% 🟢
UserMetaPostgreSQLProvider.java 100.0% 🟢
TableMetaService.java 100.0% 🟢
MetalakeMetaService.java 99.34% 🟢
SchemaMetaService.java 97.59% 🟢
JobEntity.java 97.22% 🟢
UserMetaSQLProviderFactory.java 96.55% 🟢
GroupMetaSQLProviderFactory.java 96.43% 🟢
RoleMetaSQLProviderFactory.java 96.0% 🟢
JobInfo.java 95.45% 🟢
CatalogMetaService.java 95.16% 🟢
RoleMetaService.java 94.83% 🟢
FilesetMetaService.java 93.98% 🟢
GroupMetaService.java 93.07% 🟢
UserMetaService.java 93.07% 🟢
POConverters.java 88.37% 🟢
JobPO.java 88.24% 🟢
JobManager.java 86.88% 🟢
ModelMetaService.java 81.82% 🟢
PolicyManager.java 81.4% 🟢
TopicMetaService.java 77.34% 🟢
GroupMetaMapper.java 0.0% 🔴
RoleMetaMapper.java 0.0% 🔴
UserMetaMapper.java 0.0% 🔴
server CatalogOperations.java 100.0% 🟢
FunctionOperations.java 100.0% 🟢
ModelOperations.java 100.0% 🟢
SchemaOperations.java 100.0% 🟢
TagOperations.java 100.0% 🟢
ViewOperations.java 100.0% 🟢
PolicyOperations.java 97.35% 🟢
TableOperations.java 97.18% 🟢
TopicOperations.java 97.18% 🟢
JobOperations.java 93.52% 🟢
ConfigServlet.java 88.89% 🟢
FilesetOperations.java 85.71% 🟢
MetalakeOperations.java 79.01% 🟢
AuthnOperations.java 60.0% 🟢

@paultanay

Copy link
Copy Markdown
Contributor Author

Hi @roryqi, could you please take a look at this PR when you have a chance? Thanks!

@yuqi1129
yuqi1129 requested a review from roryqi August 31, 2026 03:29
@roryqi
roryqi requested a review from mchades September 1, 2026 08:57
@mchades
mchades requested a lite review from Copilot September 1, 2026 16:37
addEx.getMessage().contains("Policy content type mismatch"),
"expected mismatch message, got: " + addEx.getMessage());
// Format arguments must be substituted — neither placeholder should survive literally.
Assertions.assertFalse(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please verify the actual diagnostic values here, not only that the format placeholders disappeared. This assertion would still pass if the message dropped both sets or formatted the wrong pair, so it does not cover the requirement in #12685 to report the expected and received supported-object sets. Assert that the original set and withExtra (and likewise withFewer below) are present, or assert the complete messages.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes validation in PolicyManager.updatePolicyEntity() so built-in policies cannot change their supportedObjectTypes during an update, and improves the resulting validation error message to include the expected/actual sets. It also adds a regression test to cover both “added type” and “removed type” scenarios for a built-in policy update.

Changes:

  • Enforce exact equality of supportedObjectTypes for built-in policy content updates (catching both additions and removals).
  • Fix the validation error message formatting by supplying the expected and actual sets.
  • Add a regression test for attempted supportedObjectTypes changes on a built-in policy.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
core/src/main/java/org/apache/gravitino/policy/PolicyManager.java Tightens built-in policy supportedObjectTypes validation and fixes error message formatting args.
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java Adds regression coverage for built-in policy content updates that try to add/remove supported object types.
Suppressed comments (2)

core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:409

  • Same coverage gap for the removal case: assert the message includes both the expected and actual supportedObjectTypes sets, not just that "%s" was substituted.
    Assertions.assertFalse(
        removeEx.getMessage().contains("%s"),
        "format args were not substituted: " + removeEx.getMessage());

core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:403

  • Avoid hard-coding the built-in policy type string here; using the enum constant keeps the test aligned if the policy type value ever changes.
                    PolicyChange.updateContent("system_iceberg_compaction", removedType)));

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

policyManager.alterPolicy(
METALAKE,
policyName,
PolicyChange.updateContent("system_iceberg_compaction", addedType)));
Comment on lines +384 to +390
Assertions.assertTrue(
addEx.getMessage().contains("Policy content type mismatch"),
"expected mismatch message, got: " + addEx.getMessage());
// Format arguments must be substituted — neither placeholder should survive literally.
Assertions.assertFalse(
addEx.getMessage().contains("%s"),
"format args were not substituted: " + addEx.getMessage());
@mchades

mchades commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

only small comments on test class, so I would merge it

@mchades
mchades merged commit cbadfbf into apache:main Sep 3, 2026
38 checks passed
jerryshao pushed a commit that referenced this pull request Sep 3, 2026
…upportedObjectTypes validation and error message (#12686) (#12882)

**Cherry-pick Information:**
- Original commit: cbadfbf
- Target branch: `branch-1.3`
- Status: ✅ Clean cherry-pick (no conflicts)

Co-authored-by: Tanay Paul <contact.tanaypaul@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

branch-1.3 Automatically cherry-pick commit to branch-1.3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug report] PolicyManager: built-in policy supportedObjectTypes check uses asymmetric set difference and omits format arguments

3 participants