From 439ceb54064aec4c7170ae701c28e1e2267fefb4 Mon Sep 17 00:00:00 2001 From: Anagh Hegde Date: Mon, 3 Apr 2023 16:50:53 +0530 Subject: [PATCH] fix: Add null check before updating the body in actions (#21781) ## Description > When an app which is connected to git which contains empty queries, is imported shows uncommitted changes on opening git sync modal. This PR fixes the issue. Fixes #21742 ## Type of change - Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? - Manual ### Test Plan > Add Testsmith test cases links that relate to this PR ### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) ## Checklist: ### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --- .../main/java/com/appsmith/git/helpers/FileUtilsImpl.java | 6 +++++- .../main/java/com/appsmith/server/helpers/GitFileUtils.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java index 81503ebba4..2bfb863f9d 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/helpers/FileUtilsImpl.java @@ -697,7 +697,11 @@ public class FileUtilsImpl implements FileInterface { if (directory.isDirectory()) { for (File dirFile : Objects.requireNonNull(directory.listFiles())) { String resourceName = dirFile.getName(); - String body = readFileAsString(directoryPath.resolve(resourceName).resolve( resourceName + CommonConstants.TEXT_FILE_EXTENSION)); + String body = ""; + Path queryPath = directoryPath.resolve(resourceName).resolve( resourceName + CommonConstants.TEXT_FILE_EXTENSION); + if (queryPath.toFile().exists()) { + body = readFileAsString(queryPath); + } Object file = readFile(directoryPath.resolve(resourceName).resolve( CommonConstants.METADATA + CommonConstants.JSON_EXTENSION), gson); actionCollectionBodyMap.put(resourceName + keySuffix, body); resource.put(resourceName + keySuffix, file); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java index e787f4d935..9df3712a49 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitFileUtils.java @@ -27,6 +27,7 @@ import com.google.gson.Gson; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.PredicateUtils; +import org.apache.commons.lang3.StringUtils; import org.eclipse.jgit.api.errors.GitAPIException; import org.springframework.context.annotation.Import; import org.springframework.stereotype.Component; @@ -419,7 +420,7 @@ public class GitFileUtils { // With the file version v4 we have split the actions and metadata separately into two files // So we need to set the body to the unpublished action String keyName = newAction.getUnpublishedAction().getName() + newAction.getUnpublishedAction().getPageId(); - if (actionBody != null && (actionBody.containsKey(keyName))) { + if (actionBody != null && (actionBody.containsKey(keyName)) && !StringUtils.isEmpty(actionBody.get(keyName))) { // For REMOTE plugin like Twilio the user actions are stored in key value pairs and hence they need to be // deserialized separately unlike the body which is stored as string in the db. if (newAction.getPluginType().toString().equals("REMOTE")) {