Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fix validation of items returned in the task runner (no-changelog) #11897

Merged

Conversation

tomi
Copy link
Contributor

@tomi tomi commented Nov 26, 2024

Summary

Fix validation and add tests

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/CAT-363/adding-a-property-to-the-item-top-level-does-not-throw

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@n8n-assistant n8n-assistant bot added the n8n team Authored by the n8n team label Nov 26, 2024
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@ivov ivov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! 🙏🏻

Let's merge this, but I have some more general questions about item validation.

@@ -9,7 +9,7 @@ export const REQUIRED_N8N_ITEM_KEYS = new Set(['json', 'binary', 'pairedItem', '
function validateTopLevelKeys(item: INodeExecutionData, itemIndex: number) {
for (const key in item) {
if (Object.prototype.hasOwnProperty.call(item, key)) {
if (REQUIRED_N8N_ITEM_KEYS.has(key)) return;
if (REQUIRED_N8N_ITEM_KEYS.has(key)) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lucky we caught this early!

  1. I notice that there is some duplication between ./packages/@n8n/task-runner/src/js-task-runner/result-validation.ts and ./packages/@n8n/task-runner/src/js-task-runner/result-validation.ts. The versions risk drifting apart as validation is updated in the Code node. Should this validation exist only once in n8n-core and be imported into the runner and into the Code node sandbox?
  2. I also notice the runner and the Code node sandbox do not share all validation, e.g. Access the properties of an item under .json, e.g. item.json and In the returned data, every key named 'json' must point to an object. are duplicated, but Please return an array of objects, one for each item you would like to output and Please return an object representing the output item. ('${executionResult}' was returned instead.) exist only in the Code node sandbox. Is this an issue also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯! Very good questions!

  1. I assume you mean between task runner and the Code Node Sandbox? The Sandbox should eventually go away entirely, so that duplication will be solved by that.
  2. I couldn't find any mismatches between the two. E.g. the Please return an array of objects is in Sandbox and also in the runner. Maybe you missed it because the code doesn't match 1:1 (the Sandbox uses some interpolation)

Copy link

cypress bot commented Nov 26, 2024

n8n    Run #8107

Run Properties:  status check passed Passed #8107  •  git commit a535e88f1a: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Project n8n
Branch Review master
Run status status check passed Passed #8107
Run duration 04m 40s
Commit git commit a535e88f1a: 🌳 master 🖥️ browsers:node18.12.0-chrome107 🤖 PR User 🗃️ e2e/*
Committer Tomi Turtiainen
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 478
View all changes introduced in this branch ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@tomi tomi merged commit a535e88 into master Nov 26, 2024
46 checks passed
@tomi tomi deleted the cat-363-adding-a-property-to-the-item-top-level-does-not-throw branch November 26, 2024 20:15
@tomi tomi changed the title fix(core): Fix validation of items returned in the task runner fix(core): Fix validation of items returned in the task runner (no-changelog) Nov 26, 2024
@github-actions github-actions bot mentioned this pull request Nov 27, 2024
@janober
Copy link
Member

janober commented Nov 27, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants