justinmclean opened a new issue, #10173:
URL: https://github.com/apache/gravitino/issues/10173

   ### What would you like to be improved?
   
   UserRoleRelPostgreSQLProvider.softDeleteUserRoleRelByUserAndRoles builds SQL 
with a MyBatis <foreach> over roleIds. When roleIds is empty, the generated 
clause becomes an empty IN (...) list, which is invalid PostgreSQL syntax and 
causes the delete operation to fail at runtime.
   
   ### How should we improve?
   
   Guard the empty-list case in SQL generation. For example, wrap the IN clause 
in a MyBatis <if test="roleIds != null and roleIds.size() > 0"> ... </if> block 
and add a safe fallback for empty lists (such as appending AND 1 = 0, or 
returning a no-op update path). This prevents invalid SQL while preserving 
expected behavior when no role IDs are provided.
   
   Here's a unit test to help:
   ```
   
   public class TestUserRoleRelPostgreSQLProvider {
   
     @Test
     void testSoftDeleteUserRoleRelByUserAndRolesWithEmptyRoles() {
       UserRoleRelPostgreSQLProvider provider = new 
UserRoleRelPostgreSQLProvider();
       String script = provider.softDeleteUserRoleRelByUserAndRoles(1L, 
Collections.emptyList());
   
       SqlSource sqlSource =
           new XMLLanguageDriver().createSqlSource(new Configuration(), script, 
Map.class);
       Map<String, Object> params = new HashMap<>();
       params.put("userId", 1L);
       params.put("roleIds", Collections.emptyList());
   
       BoundSql boundSql = sqlSource.getBoundSql(params);
       String normalizedSql = boundSql.getSql().replaceAll("\\s+", " ").trim();
   
       Assertions.assertFalse(
           normalizedSql.matches(".*\\bIN\\s*\\(\\s*\\).*"),
           "Empty roleIds should not generate invalid SQL IN (...) with no 
values");
     }
   }
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to