You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "paultanay (via GitHub)" <gi...@apache.org> on 2026/08/27 16:46:57 UTC

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

paultanay opened a new pull request, #12686:
URL: https://github.com/apache/gravitino/pull/12686

   ## 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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#discussion_r3906426635


##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -354,6 +354,61 @@ public void testAlterPolicy() {
     Assertions.assertTrue(enabledPolicy.enabled());
   }
 
+  @Test
+  public void testAlterBuiltInPolicyContent() {
+    String policyName = "policy_" + UUID.randomUUID().toString().replace("-", "");
+    policyManager.createPolicy(
+        METALAKE,
+        policyName,
+        Policy.BuiltInType.ICEBERG_COMPACTION,
+        null,
+        true,
+        PolicyContents.icebergDataCompaction());
+
+    // Adding a type not in the original set must be rejected.
+    Set<MetadataObject.Type> withExtra =
+        ImmutableSet.of(
+            MetadataObject.Type.CATALOG,
+            MetadataObject.Type.SCHEMA,
+            MetadataObject.Type.TABLE,
+            MetadataObject.Type.FILESET);
+    PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(), withExtra, null);
+    IllegalArgumentException addEx =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                policyManager.alterPolicy(
+                    METALAKE,
+                    policyName,
+                    PolicyChange.updateContent("system_iceberg_compaction", addedType)));
+    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());

Review Comment:
   The test currently only checks that "%s" placeholders are gone; it doesn't verify the updated message actually includes the expected/actual supportedObjectTypes sets (which is part of this PR's behavior change). Asserting both set values appear will prevent regressions that still remove "%s" but omit the sets.
   
   This issue also appears on line 407 of the same file.



##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -354,6 +354,61 @@ public void testAlterPolicy() {
     Assertions.assertTrue(enabledPolicy.enabled());
   }
 
+  @Test
+  public void testAlterBuiltInPolicyContent() {
+    String policyName = "policy_" + UUID.randomUUID().toString().replace("-", "");
+    policyManager.createPolicy(
+        METALAKE,
+        policyName,
+        Policy.BuiltInType.ICEBERG_COMPACTION,
+        null,
+        true,
+        PolicyContents.icebergDataCompaction());
+
+    // Adding a type not in the original set must be rejected.
+    Set<MetadataObject.Type> withExtra =
+        ImmutableSet.of(
+            MetadataObject.Type.CATALOG,
+            MetadataObject.Type.SCHEMA,
+            MetadataObject.Type.TABLE,
+            MetadataObject.Type.FILESET);
+    PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(), withExtra, null);
+    IllegalArgumentException addEx =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                policyManager.alterPolicy(
+                    METALAKE,
+                    policyName,
+                    PolicyChange.updateContent("system_iceberg_compaction", addedType)));

Review Comment:
   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.
   
   This issue also appears on line 403 of the same file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "paultanay (via GitHub)" <gi...@apache.org>.
paultanay commented on PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#issuecomment-5460583589

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on code in PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#discussion_r3906373006


##########
core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java:
##########
@@ -354,6 +354,61 @@ public void testAlterPolicy() {
     Assertions.assertTrue(enabledPolicy.enabled());
   }
 
+  @Test
+  public void testAlterBuiltInPolicyContent() {
+    String policyName = "policy_" + UUID.randomUUID().toString().replace("-", "");
+    policyManager.createPolicy(
+        METALAKE,
+        policyName,
+        Policy.BuiltInType.ICEBERG_COMPACTION,
+        null,
+        true,
+        PolicyContents.icebergDataCompaction());
+
+    // Adding a type not in the original set must be rejected.
+    Set<MetadataObject.Type> withExtra =
+        ImmutableSet.of(
+            MetadataObject.Type.CATALOG,
+            MetadataObject.Type.SCHEMA,
+            MetadataObject.Type.TABLE,
+            MetadataObject.Type.FILESET);
+    PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(), withExtra, null);
+    IllegalArgumentException addEx =
+        Assertions.assertThrows(
+            IllegalArgumentException.class,
+            () ->
+                policyManager.alterPolicy(
+                    METALAKE,
+                    policyName,
+                    PolicyChange.updateContent("system_iceberg_compaction", addedType)));
+    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(

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades merged PR #12686:
URL: https://github.com/apache/gravitino/pull/12686


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#issuecomment-5450664555

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|68.47% **`+0.03%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|81.4%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|19.74%|:red_circle:|
   |api|52.07%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |authorization-ranger|4.38%|:red_circle:|
   |aws|53.54%|:green_circle:|
   |azure|32.1%|:red_circle:|
   |catalog-common|9.9%|:red_circle:|
   |catalog-fileset|80.21%|:green_circle:|
   |catalog-glue|69.24%|:green_circle:|
   |catalog-hive|82.96%|:green_circle:|
   |catalog-jdbc-common|45.69%|:green_circle:|
   |catalog-jdbc-doris|82.44%|:green_circle:|
   |catalog-jdbc-mysql|79.33%|:green_circle:|
   |catalog-jdbc-postgresql|83.39%|:green_circle:|
   |catalog-jdbc-starrocks|79.16%|:green_circle:|
   |catalog-kafka|76.99%|:green_circle:|
   |catalog-lakehouse-generic|60.55%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|84.26%|:green_circle:|
   |catalog-model|77.99%|:green_circle:|
   |cli|44.48%|:green_circle:|
   |client-java|77.44%|:green_circle:|
   |common|55.76%|:green_circle:|
   |core|83.57% **`-0.02%`**|:green_circle:|
   |filesystem-hadoop3|76.45%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|50.29%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|32.2%|:red_circle:|
   |hadoop-auth|68.0%|:green_circle:|
   |hadoop-common|17.84%|:red_circle:|
   |hive-metastore-common|53.4%|:green_circle:|
   |iceberg-aliyun-bundle|0.0%|:red_circle:|
   |iceberg-common|64.75%|:green_circle:|
   |iceberg-rest-server|75.61%|:green_circle:|
   |idp-basic|85.98%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|62.92%|:green_circle:|
   |lance-common|32.63%|:red_circle:|
   |lance-rest-server|63.87%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|83.17%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|88.04%|:green_circle:|
   |server-common|80.5%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|48.92%|:green_circle:|
   |tencent|69.84%|:green_circle:|
   |trino-connector|47.44%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |core|[PolicyManager.java](https://github.com/paultanay/gravitino/blob/e13034c1d417f91e3eccf119aa497b2d44e323d8/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java)|81.4%|:green_circle:|
   
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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

Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on PR #12686:
URL: https://github.com/apache/gravitino/pull/12686#issuecomment-5524284461

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org