tanishqgandhi1908 commented on code in PR #6872:
URL: https://github.com/apache/texera/pull/6872#discussion_r3856008412


##########
file-service/src/main/scala/org/apache/texera/service/resource/ModelResource.scala:
##########
@@ -408,4 +460,341 @@ class ModelResource extends LazyLogging {
   ): DashboardModel = {
     withTransaction(context)(ctx => getDashboardModel(ctx, mid, None))
   }
+
+  // 
===========================================================================
+  // Versioning
+  // 
===========================================================================
+
+  @POST
+  @RolesAllowed(Array("REGULAR", "ADMIN"))
+  @Path("/{mid}/version/create")
+  @Consumes(Array(MediaType.TEXT_PLAIN))
+  def createModelVersion(
+      versionName: String,
+      @PathParam("mid") mid: Integer,
+      @Auth user: SessionUser
+  ): DashboardModelVersion = {
+    val uid = user.getUid
+    withTransaction(context) { ctx =>
+      if (!userHasWriteAccess(ctx, mid, uid)) {
+        throw new ForbiddenException(ERR_USER_HAS_NO_ACCESS_TO_MODEL_MESSAGE)
+      }
+
+      val model = getModelByID(ctx, mid)
+      val modelName = model.getName
+      val repositoryName = model.getRepositoryName
+
+      // Check if there are any changes in LakeFS before creating a new version
+      val diffs = withLakeFSErrorHandling {
+        LakeFSStorageClient.retrieveUncommittedObjects(repoName = 
repositoryName)
+      }
+
+      if (diffs.isEmpty) {
+        throw new WebApplicationException(
+          "No changes detected in model. Version creation aborted.",
+          Response.Status.BAD_REQUEST
+        )
+      }
+
+      // Generate a new version name
+      val versionCount = ctx
+        .selectCount()
+        .from(MODEL_VERSION)
+        .where(MODEL_VERSION.MID.eq(mid))
+        .fetchOne(0, classOf[Int])
+
+      val sanitizedVersionName = 
Option(versionName).filter(_.nonEmpty).getOrElse("")
+      val newVersionName = if (sanitizedVersionName.isEmpty) {
+        s"v${versionCount + 1}"
+      } else {
+        s"v${versionCount + 1} - $sanitizedVersionName"

Review Comment:
   Good catch — the stranded staged file is the bad part. Moved the length 
check ahead of `createCommit` and return a 400. The test asserts the retry 
path: after the rejection the staged change is still there and a shorter name 
commits normally.
   
   



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