This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new bfe7bbfefe [8158] improvement: display an error if both alias and 
version are null in UpdateModelVersionAliases (#8192)
bfe7bbfefe is described below

commit bfe7bbfefe46bf0698802d7c298ef1bff89d0d45
Author: Sambhavi Pandey <[email protected]>
AuthorDate: Wed Aug 20 10:39:40 2025 +0530

    [8158] improvement: display an error if both alias and version are null in 
UpdateModelVersionAliases (#8192)
    
    ### What changes were proposed in this pull request?
    display an error if both alias and version are null in 
UpdateModelVersionAliases
    
    ### Why are the changes needed?
    
    To improve error handling
    
    Fix: #8158
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    Unit testing
---
 .../cli/commands/UpdateModelVersionAliases.java     |  4 +++-
 .../org/apache/gravitino/cli/TestModelCommands.java | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateModelVersionAliases.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateModelVersionAliases.java
index 9de73d0a8d..384b58da76 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateModelVersionAliases.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateModelVersionAliases.java
@@ -114,7 +114,9 @@ public class UpdateModelVersionAliases extends Command {
     if (alias != null && version != null) {
       exitWithError("Cannot specify both alias and version");
     }
-
+    if (alias == null && version == null) {
+      exitWithError("Either alias or version must be specified");
+    }
     return this;
   }
 }
diff --git 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java
index e0f1797e69..155778381c 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestModelCommands.java
@@ -1146,4 +1146,25 @@ public class TestModelCommands {
 
     Assertions.assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
   }
+
+  @Test
+  void testUpdateModelVersionAliasesByNullAliasAndVersion() {
+    Main.useExit = false;
+    
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
+    when(mockCommandLine.hasOption(GravitinoOptions.ALIAS)).thenReturn(false);
+    
when(mockCommandLine.getOptionValues(GravitinoOptions.ALIAS)).thenReturn(null);
+    
when(mockCommandLine.hasOption(GravitinoOptions.VERSION)).thenReturn(false);
+    
when(mockCommandLine.getOptionValue(GravitinoOptions.VERSION)).thenReturn(null);
+    
when(mockCommandLine.hasOption(GravitinoOptions.NEW_ALIAS)).thenReturn(true);
+    when(mockCommandLine.getOptionValues(GravitinoOptions.NEW_ALIAS))
+        .thenReturn(new String[] {"aliasA", "aliasB"});
+
+    GravitinoCommandLine commandLine =
+        spy(
+            new GravitinoCommandLine(
+                mockCommandLine, mockOptions, CommandEntities.MODEL, 
CommandActions.UPDATE));
+
+    Assertions.assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
+  }
 }

Reply via email to