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

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-6612-42027e8c38d248a60cab32871887bc754ef311b5
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 3a671c31ffe7f5a48da5b2e98841b0d55e176acc
Author: Prateek Ganigi <[email protected]>
AuthorDate: Mon Jul 20 12:37:38 2026 -0700

    fix(computing-unit): return 404 instead of 500 when getOwner is called for 
a nonexistent unit (#6612)
    
    ### What changes were proposed in this PR?
    ComputingUnitAccessResource.getOwner (GET
    /access/computing-unit/owner/{cuid}) threw a plain
    IllegalArgumentException when the requested unit didn't exist:
    
    
    if (unit == null) {
      throw new IllegalArgumentException("Computing unit does not exist")
    }
    
    The service registers no ExceptionMapper for IllegalArgumentException
    (only UnauthorizedExceptionMapper), so it fell through to Dropwizard's
    default LoggingExceptionMapper and surfaced as an opaque HTTP 500 rather
    than a proper client error.
    
    This PR throws jakarta.ws.rs.NotFoundException instead, so a nonexistent
    unit now returns a 404. This is the same unmapped-exception→500 pattern
    fixed for grantAccess/revokeAccess in #6446; getOwner was outside that
    PR's diff. The choice of 404 and the message style match the
    same-service convention in ComputingUnitManagingResource (throw new
    NotFoundException(s"Computing unit with cuid=$cuid does not exist.")).
    
    Note: getOwner also dereferences userDao.fetchOneByUid(uid).getEmail
    without a null-check. That path is unreachable in practice,
    workflow_computing_unit.uid is REFERENCES "user"(uid) ON DELETE CASCADE,
    so a unit cannot outlive its owner, so it's intentionally left out of
    this focused fix and tracked with the broader coverage work in #6490.
    
    ### Any related issues, documentation, discussions?
    Closes #6475
    
    ### How was this PR tested?
    Added a getOwner test to ComputingUnitAccessResourceSpec (embedded
    Postgres via MockTexeraDB, reusing the wiring from #6446) that requests
    a nonexistent cuid and asserts the JAX-RS NotFoundException and its
    resolved 404 status:
    
    "getOwner" should "reject a nonexistent computing unit with a 404
    instead of crashing" in {
      val ex = intercept[NotFoundException] {
        accessResource.getOwner(ownerSession, nonExistentCuid)
      }
      ex.getResponse.getStatus shouldEqual 404
    ex.getMessage should include(s"Computing unit with cuid=$nonExistentCuid
    does not exist")
    }
    Verified red→green: against the old IllegalArgumentException the test
    fails with "Expected exception jakarta.ws.rs.NotFoundException … but
    java.lang.IllegalArgumentException was thrown"; after the fix all 9
    tests in the spec pass. Scalafmt clean.
    
    Run:
    
    sbt "ComputingUnitManagingService/testOnly
    org.apache.texera.service.resource.ComputingUnitAccessResourceSpec"
    
    ### Was this PR authored or co-authored using generative AI tooling?
    Co-authored with Claude Opus 4.8 in compliance with ASF.
---
 .../service/resource/ComputingUnitAccessResource.scala    |  5 ++++-
 .../resource/ComputingUnitAccessResourceSpec.scala        | 15 ++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git 
a/computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala
 
b/computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala
index 9ed77ead1f..88fba414b1 100644
--- 
a/computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala
+++ 
b/computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitAccessResource.scala
@@ -214,7 +214,10 @@ class ComputingUnitAccessResource {
       val workflowComputingUnitDao = new 
WorkflowComputingUnitDao(ctx.configuration())
       val unit = workflowComputingUnitDao.fetchOneByCuid(cuid)
       if (unit == null) {
-        throw new IllegalArgumentException("Computing unit does not exist")
+        // JAX-RS exception so it maps to 404: the service registers no 
ExceptionMapper
+        // for IllegalArgumentException, which would otherwise surface as an 
HTTP 500.
+        // Message style matches ComputingUnitManagingResource's 
nonexistent-unit error.
+        throw new NotFoundException(s"Computing unit with cuid=$cuid does not 
exist.")
       }
 
       val uid = unit.getUid
diff --git 
a/computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala
 
b/computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala
index 56c098049a..7637c99d26 100644
--- 
a/computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala
+++ 
b/computing-unit-managing-service/src/test/scala/org/apache/texera/service/resource/ComputingUnitAccessResourceSpec.scala
@@ -19,7 +19,7 @@
 
 package org.apache.texera.service.resource
 
-import jakarta.ws.rs.{BadRequestException, ForbiddenException}
+import jakarta.ws.rs.{BadRequestException, ForbiddenException, 
NotFoundException}
 import org.apache.texera.auth.SessionUser
 import org.apache.texera.common.config.ComputingUnitConfig
 import org.apache.texera.dao.MockTexeraDB
@@ -90,6 +90,7 @@ class ComputingUnitAccessResourceSpec
   }
 
   private val nonExistentEmail: String = "[email protected]"
+  private val nonExistentCuid: Integer = 999999
 
   lazy val accessResource = new ComputingUnitAccessResource()
 
@@ -201,4 +202,16 @@ class ComputingUnitAccessResourceSpec
     ex.getResponse.getStatus shouldEqual 403
     ex.getMessage should include("does not have permission to revoke access")
   }
+
+  // 
===========================================================================
+  // getOwner
+  // 
===========================================================================
+
+  "getOwner" should "reject a nonexistent computing unit with a 404 instead of 
crashing" in {
+    val ex = intercept[NotFoundException] {
+      accessResource.getOwner(ownerSession, nonExistentCuid)
+    }
+    ex.getResponse.getStatus shouldEqual 404
+    ex.getMessage should include(s"Computing unit with cuid=$nonExistentCuid 
does not exist")
+  }
 }

Reply via email to