fix(core): Restore workflow ID during execution creation (#8031)

## Summary
Restore workflow ID during execution creation removed by [this
PR](https://github.com/n8n-io/n8n/pull/8002/files#diff-c8cbb62ca9ab2ae45e5f565cd8c63fff6475809a6241ea0b90acc575615224af).
The missing workflow ID, and more generally the fact that `workflow.id`
is optional when it should not be, causes `PermissionChecker.check` to
misreport a credential as inaccessible when it should be accessible.

More generally, start reporting ID-less workflows so we can root them
out and prevent this at type level.

## Related tickets and issues

https://n8nio.slack.com/archives/C035KBDA917/p1702539465555529
This commit is contained in:
Iván Ovejero
2023-12-14 18:13:12 +01:00
committed by GitHub
parent 53c0b49d15
commit c5e6ba8cdd
4 changed files with 27 additions and 4 deletions

View File

@@ -13,7 +13,13 @@ import type {
INodeTypes,
IRun,
} from 'n8n-workflow';
import { Workflow, NodeOperationError, sleep, ApplicationError } from 'n8n-workflow';
import {
Workflow,
NodeOperationError,
sleep,
ApplicationError,
ErrorReporterProxy as EventReporter,
} from 'n8n-workflow';
import * as Db from '@/Db';
import * as ResponseHelper from '@/ResponseHelper';
@@ -130,7 +136,15 @@ export class Worker extends BaseCommand {
{ extra: { executionId } },
);
}
const workflowId = fullExecutionData.workflowData.id!;
const workflowId = fullExecutionData.workflowData.id!; // @tech_debt Ensure this is not optional
if (!workflowId) {
EventReporter.report('Detected ID-less workflow', {
level: 'info',
extra: { execution: fullExecutionData },
});
}
this.logger.info(
`Start job: ${job.id} (Workflow ID: ${workflowId} | Execution: ${executionId})`,
);