refactor: Add native Python runner runtime env var (#19109)

This commit is contained in:
Iván Ovejero
2025-09-03 09:35:25 +02:00
committed by GitHub
parent 63a3502283
commit 89fc91bed6
6 changed files with 42 additions and 40 deletions

View File

@@ -60,6 +60,7 @@ export interface FrontendSettings {
versionCli: string;
nodeJsVersion: string;
concurrency: number;
isNativePythonRunnerEnabled: boolean;
authCookie: {
secure: boolean;
};

View File

@@ -131,6 +131,8 @@ export class FrontendService {
nodeJsVersion: process.version.replace(/^v/, ''),
versionCli: N8N_VERSION,
concurrency: this.globalConfig.executions.concurrency.productionLimit,
isNativePythonRunnerEnabled:
this.globalConfig.taskRunners.enabled && process.env.N8N_NATIVE_PYTHON_RUNNER === 'true',
authCookie: {
secure: this.globalConfig.auth.cookie.secure,
},

View File

@@ -102,6 +102,7 @@ export const defaultSettings: FrontendSettings = {
versionCli: '',
nodeJsVersion: '',
concurrency: -1,
isNativePythonRunnerEnabled: false,
versionNotifications: {
enabled: true,
endpoint: '',

View File

@@ -241,6 +241,11 @@ const parameterOptions = computed(() => {
const options = hasRemoteMethod.value ? remoteParameterOptions.value : props.parameter.options;
const safeOptions = (options ?? []).filter(isValidParameterOption);
// temporary filter until native Python runner is GA
if (props.parameter.name === 'language' && !settingsStore.isNativePythonRunnerEnabled) {
return safeOptions.filter((o) => o.value !== 'pythonNative');
}
return safeOptions;
});

View File

@@ -70,6 +70,8 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
const concurrency = computed(() => settings.value.concurrency);
const isNativePythonRunnerEnabled = computed(() => settings.value.isNativePythonRunnerEnabled);
const isConcurrencyEnabled = computed(() => concurrency.value !== -1);
const isPublicApiEnabled = computed(() => api.value.enabled);
@@ -329,6 +331,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
security,
nodeJsVersion,
concurrency,
isNativePythonRunnerEnabled,
isConcurrencyEnabled,
isPublicApiEnabled,
isSwaggerUIEnabled,

View File

@@ -3,7 +3,6 @@ import { NodesConfig, TaskRunnersConfig } from '@n8n/config';
import { Container } from '@n8n/di';
import set from 'lodash/set';
import {
type INodeProperties,
NodeConnectionTypes,
UserError,
type CodeExecutionMode,
@@ -26,7 +25,7 @@ import { PythonTaskRunnerSandbox } from './PythonTaskRunnerSandbox';
import { getSandboxContext } from './Sandbox';
import { addPostExecutionWarning, standardizeOutput } from './utils';
const { CODE_ENABLE_STDOUT, N8N_NATIVE_PYTHON_RUNNER } = process.env;
const { CODE_ENABLE_STDOUT } = process.env;
class PythonDisabledError extends UserError {
constructor() {
@@ -36,43 +35,6 @@ class PythonDisabledError extends UserError {
}
}
const getV2LanguageProperty = (): INodeProperties => {
const options = [
{
name: 'JavaScript',
value: 'javaScript',
action: 'Code in JavaScript',
},
{
name: 'Python (Beta)',
value: 'python',
action: 'Code in Python (Beta)',
},
];
if (N8N_NATIVE_PYTHON_RUNNER === 'true') {
options.push({
name: 'Python (Native) (Beta)',
value: 'pythonNative',
action: 'Code in Python (Native) (Beta)',
});
}
return {
displayName: 'Language',
name: 'language',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
'@version': [2],
},
},
options,
default: 'javaScript',
};
};
export class Code implements INodeType {
description: INodeTypeDescription = {
displayName: 'Code',
@@ -108,7 +70,35 @@ export class Code implements INodeType {
],
default: 'runOnceForAllItems',
},
getV2LanguageProperty(),
{
displayName: 'Language',
name: 'language',
type: 'options',
noDataExpression: true,
displayOptions: {
show: {
'@version': [2],
},
},
options: [
{
name: 'JavaScript',
value: 'javaScript',
action: 'Code in JavaScript',
},
{
name: 'Python (Beta)',
value: 'python',
action: 'Code in Python (Beta)',
},
{
name: 'Python (Native) (Beta)',
value: 'pythonNative',
action: 'Code in Python (Native) (Beta)',
},
],
default: 'javaScript',
},
{
displayName: 'Language',
name: 'language',