mattcasters commented on code in PR #9194:
URL: https://github.com/apache/hop/pull/9194#discussion_r4435529358
##########
plugins/actions/truncatetables/src/main/java/org/apache/hop/workflow/actions/truncatetables/ActionTruncateTables.java:
##########
@@ -153,81 +147,98 @@ public Result execute(Result previousResult, int nr) {
return result;
}
}
- if (connection != null) {
-
- try (Database db =
- new Database(
- this, this, getParentWorkflowMeta().findDatabase(connection,
getVariables()))) {
- db.connect();
- if (argFromPrevious && rows != null) { // Copy the input row to the
(command line) arguments
-
- for (int iteration = 0;
- iteration < rows.size() && !parentWorkflow.isStopped() &&
continueProcess;
- iteration++) {
- resultRow = rows.get(iteration);
-
- // Get values from previous result
- String tableNamePrevious = resultRow.getString(0, null);
- String schemaNamePrevious = resultRow.getString(1, null);
-
- if (!Utils.isEmpty(tableNamePrevious)) {
- if (isDetailed()) {
- logDetailed(
- BaseMessages.getString(
- PKG,
- "ActionTruncateTables.ProcessingRow",
- tableNamePrevious,
- schemaNamePrevious));
- }
-
- // let's truncate table
- if (truncateTables(tableNamePrevious, schemaNamePrevious, db)) {
- updateSuccess();
+ String realConnection = resolve(connection);
+ if (Utils.isEmpty(realConnection)) {
+ updateErrors();
+ logError(BaseMessages.getString(PKG,
"ActionTruncateTables.NoDbConnection"));
+ } else {
+ DatabaseMeta databaseMeta =
+ getParentWorkflowMeta() == null
+ ? null
+ : getParentWorkflowMeta().findDatabase(realConnection,
getVariables());
Review Comment:
**[bug]** `findDatabase` used to run inside the `try` that builds
`Database`, so a `HopRuntimeException` from the metadata serializer (corrupt
JSON, I/O error, and so on) was caught, counted with `updateErrors()`, and
returned as `result=false`. It now runs before that `try`. `Workflow` does not
turn an exception from `execute()` into a failed action result: the sequential
path rethrows and `startExecution` replaces the workflow result and stops, so
the failure hop of this action is not taken. A missing connection still returns
null and is handled; only the throwing lookup path regressed.
**Suggestion:** Keep the null check, but call `findDatabase` inside the same
`try/catch (Exception)` as `db.connect()` (or wrap the lookup and the database
block in one try). On that exception, keep `updateErrors()` and
`ActionTruncateTables.Error.RunningEntry` so the action fails instead of
aborting the workflow.
--
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]