From 941be8c58d8e25eaf2cce30e1f2220cb4e6420e4 Mon Sep 17 00:00:00 2001 From: Nidhi Date: Wed, 18 Nov 2020 14:25:55 +0530 Subject: [PATCH] Fixed check for incorrect dynamic bindings (#1775) * Fixed check for incorrect dynamic bindings --- .../java/com/appsmith/server/constants/FieldName.java | 1 + .../server/services/LayoutActionServiceImpl.java | 7 +++++-- .../appsmith/server/services/LayoutServiceTest.java | 10 +++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java index 7c906e954a..08efddb658 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/constants/FieldName.java @@ -17,6 +17,7 @@ public class FieldName { public static String PLUGIN = "plugin"; public static String DEFAULT_PAGE_NAME = "Page1"; public static String TYPE = "type"; + public static final String WIDGET_ID = "widgetId"; public static String WIDGET_NAME = "widgetName"; public static String DYNAMIC_BINDINGS = "dynamicBindings"; public static String DYNAMIC_BINDING_PATH_LIST = "dynamicBindingPathList"; diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java index b5909a6531..aab017e462 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/LayoutActionServiceImpl.java @@ -455,10 +455,13 @@ public class LayoutActionServiceImpl implements LayoutActionService { } } if (parent == null) { - throw new AppsmithException(AppsmithError.INVALID_DYNAMIC_BINDING_REFERENCE, nextKey); + log.error("Unable to find dynamically bound key {} for the widget with id {}", nextKey, dsl.get(FieldName.WIDGET_ID)); + break; } } - dynamicBindings.addAll(MustacheHelper.extractMustacheKeysFromFields(parent)); + if(parent != null) { + dynamicBindings.addAll(MustacheHelper.extractMustacheKeysFromFields(parent)); + } } } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java index 9cc66f23ce..3027da9c9a 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/LayoutServiceTest.java @@ -480,9 +480,13 @@ public class LayoutServiceTest { StepVerifier .create(testMono) - .expectErrorMatches(throwable -> throwable instanceof AppsmithException && - throwable.getMessage().equals(AppsmithError.INVALID_DYNAMIC_BINDING_REFERENCE.getMessage("dynamicGet_IncorrectKey"))) - .verify(); + .assertNext(layout -> { + assertThat(layout).isNotNull(); + assertThat(layout.getId()).isNotNull(); + assertThat(layout.getDsl().get("key")).isEqualTo("value-updated"); + assertThat(layout.getLayoutOnLoadActions()).hasSize(0); + }) + .verifyComplete(); } @After