{"record":{"id":"657f06b6a5696f16","repo":"kestra-io/kestra","slug":"you-cannot-set-a-namespace-both-as-the-function-ar","errorCode":null,"errorMessage":"You cannot set a namespace both as the function argument and inside the URI","messagePattern":"You cannot set a namespace both as the function argument and inside the URI","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/AbstractFileFunction.java","lineNumber":183,"sourceCode":"\n    private String checkIfFileFromAllowedNamespaceAndReturnIt(URI path, String tenantId, String fromNamespace) {\n\n        String namespace = extractNamespace(path);\n        namespaceService.get().checkAllowedNamespace(tenantId, namespace, tenantId, fromNamespace);\n        return namespace;\n    }\n\n    private String checkEnabledLocalFileAndReturnNamespace(Map<String, Object> args, Map<String, String> flow) {\n        if (!localFilesConfiguration.enableFileFunctions()) {\n            throw new SecurityException(\"The file:// protocol has been disabled inside the Kestra configuration.\");\n        }\n\n        return (String) Optional.ofNullable(args.get(NAMESPACE)).orElse(flow.get(NAMESPACE));\n    }\n\n    private String checkedAllowedNamespaceAndReturnNamespace(Map<String, Object> args, URI nsFileUri, String tenantId, Map<String, String> flow) {\n        if (args.get(NAMESPACE) != null && nsFileUri.getAuthority() != null) {\n            throw new IllegalArgumentException(\"You cannot set a namespace both as the function argument and inside the URI\");\n        }\n\n        // we will transform nsfile URI into a kestra URI so it is handled seamlessly by all functions\n        String customNs = Optional.ofNullable((String) args.get(NAMESPACE)).orElse(nsFileUri.getAuthority());\n        if (customNs != null) {\n            namespaceService.get().checkAllowedNamespace(tenantId, customNs, tenantId, flow.get(NAMESPACE));\n        }\n        return Optional.ofNullable(customNs).orElse(flow.get(NAMESPACE));\n    }\n\n    @VisibleForTesting\n    String extractNamespace(URI path) {\n        // Extract namespace from the path, it should be of the form: kestra:///{namespace}/{flowId}/executions/{executionId}/tasks/{taskId}/{taskRunId}/{fileName}'\n        // To extract the namespace, we must do it step by step as namespace and taskId can contain the words 'executions' and 'tasks'\n        String namespace = path.toString().substring(KESTRA_SCHEME.length());\n        if (!EXECUTION_FILE.matcher(namespace).matches()) {\n            throw new IllegalArgumentException(\"Unable to read the file '\" + path + \"' as it is not an execution file\");\n        }","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/AbstractFileFunction.java#L165-L201","documentation":"checkedAllowedNamespaceAndReturnNamespace() throws IllegalArgumentException when a namespace:// URI carries an authority (the namespace inside the URI) AND the caller also passes the 'namespace' function argument. Only one source of namespace is allowed. The surrounding catch wraps it into a PebbleException.","triggerScenarios":"Calling {{ read('namespace://company.team/data.txt', namespace='company.team') }} — both the URI authority and the argument specify a namespace.","commonSituations":"Copy-paste from a template that used the argument form onto a URI that already embeds the namespace; defensive over-specification; refactoring between the two forms without removing one.","solutions":["Specify the namespace in exactly one place: either in the URI (namespace://company.team/file) OR via the argument (read('namespace:///file', namespace='company.team')).","Prefer the URI-authority form for readability and drop the namespace argument.","Validate that the two would match, then delete the redundant one."],"exampleFix":"// before\n{{ read('namespace://company.team/data.txt', namespace='company.team') }}\n// after\n{{ read('namespace://company.team/data.txt') }}","handlingStrategy":"validation","validationCode":"// Pebble: specify namespace in exactly one place\n{{ read('namespace://company.team/data.txt') }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass both a namespace:// authority and the namespace argument.","Pick one namespace source and delete the other.","Validate that the two, if both present, do not contradict."],"tags":["pebble","function","argument","namespace","uri"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}