Skip to content

Commit

Permalink
chore: add null check for the datasource (#34691)
Browse files Browse the repository at this point in the history
## Description
> [!TIP]  
> _Add a TL;DR when the description is longer than 500 words or
extremely technical (helps the content, marketing, and DevRel team)._
>
> _Please also include relevant motivation and context. List any
dependencies that are required for this change. Add links to Notion,
Figma or any other documents that might be relevant to the PR._


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Git"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9789434801>
> Commit: 52a84a3
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9789434801&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Git`
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved the validation and assignment logic for data sources during
action import to ensure proper association and prevent errors when data
source or plugin IDs are missing.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
AnaghHegde authored Jul 4, 2024
1 parent 4bbe28a commit 6c48a39
Showing 1 changed file with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static com.appsmith.external.helpers.AppsmithBeanUtils.copyNestedNonNullProperties;
Expand Down Expand Up @@ -319,30 +318,14 @@ private Mono<ImportActionResultDTO> createImportNewActionsMono(
branchedNewAction,
newAction);

// Check if the action has datasource present
// Check if the action has datasource is present and contains pluginId
Datasource datasource =
newAction.getUnpublishedAction().getDatasource();
if (datasource == null || datasource.getPluginId() == null) {
if (datasource != null && datasource.getPluginId() == null) {
// Since the datasource are not yet saved to db, if we don't update the action with
// correct datasource,
// the action ave will fail due to validation
final String datasourceId = Objects.requireNonNull(newAction
.getUnpublishedAction()
.getDatasource())
.getId()
!= null
? newAction
.getUnpublishedAction()
.getDatasource()
.getId()
: "";
datasource = mappedImportableResourcesDTO.getDatasourceDryRunQueries().values().stream()
.flatMap(List::stream)
.filter(ds -> ds.getId().equals(datasourceId))
.findFirst()
.orElse(datasource);
datasource.setIsAutoGenerated(false);
newAction.getUnpublishedAction().setDatasource(datasource);
updateDatasourceInAction(newAction, mappedImportableResourcesDTO, datasource);
}

// Check if the action has gitSyncId and if it's already in DB
Expand Down Expand Up @@ -575,4 +558,21 @@ private void putActionIdInMap(NewAction newAction, ImportActionResultDTO importA
}
}
}

private void updateDatasourceInAction(
NewAction newAction, MappedImportableResourcesDTO mappedImportableResourcesDTO, Datasource datasource) {
if (!StringUtils.isEmpty(
newAction.getUnpublishedAction().getDatasource().getId())) {
final String datasourceId =
newAction.getUnpublishedAction().getDatasource().getId();
datasource = mappedImportableResourcesDTO.getDatasourceDryRunQueries().values().stream()
.flatMap(List::stream)
.filter(ds -> ds.getId().equals(datasourceId))
.findFirst()
.orElse(datasource);
datasource.setIsAutoGenerated(false);
}

newAction.getUnpublishedAction().setDatasource(datasource);
}
}

0 comments on commit 6c48a39

Please sign in to comment.