{"record":{"id":"b9e2997e564459aa","repo":"cube-js/cube","slug":"error-while-calling-filter","errorCode":null,"errorMessage":"Error while calling filter: {}","messagePattern":"Error while calling filter: (.+?)","errorType":"exception","errorClass":"minijinja::Error","httpStatus":null,"severity":"error","filePath":"packages/cubejs-backend-native/src/template/engine_python.rs","lineNumber":54,"sourceCode":"                    other.kind()\n                ))\n            }\n        };\n\n        engine.add_filter(\n            filter_name.value(cx),\n            move |_state: &mj::State,\n                  args: &[mj::value::Value]|\n                  -> Result<mj::value::Value, mj::Error> {\n                let mut arguments = Vec::with_capacity(args.len());\n\n                for arg in args {\n                    arguments.push(from_minijinja_value(arg)?);\n                }\n\n                match python_fn_call_sync(&py_fun, arguments) {\n                    Ok(r) => Ok(to_minijinja_value(r)),\n                    Err(err) => Err(mj::Error::new(\n                        minijinja::ErrorKind::InvalidOperation,\n                        format!(\"Error while calling filter: {}\", err),\n                    )),\n                }\n            },\n        );\n    }\n\n    Ok(())\n}\n","sourceCodeStart":36,"sourceCodeEnd":65,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/packages/cubejs-backend-native/src/template/engine_python.rs#L36-L65","documentation":"The Python extension for MiniJinja wraps Python callables as Jinja filters. When a template invokes such a filter and the underlying Python function raises, `python_fn_call_sync` returns an error and the wrapper converts it into a MiniJinja `InvalidOperation` error with this message. The original Python traceback text is embedded in `{err}`.","triggerScenarios":"A template calls a registered Python filter/function and that function throws (any Python exception) or its arguments cannot be converted from MiniJinja values (see `from_minijinja_value` failures).","commonSituations":"User-defined Python filter raising on unexpected input (None where a number is expected), type errors from mismatched arguments, missing Python dependencies inside the native runtime.","solutions":["Read the `{err}` suffix — it contains the Python exception and usually the failing line.","Fix or add input validation inside the Python filter function.","Ensure all argument types passed from the template are convertible (numbers, strings, seqs, string-keyed maps).","Test the filter function directly in Python with representative template inputs."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = my_filter(value)\nexcept Exception as e:\n    # the MiniJinja error embeds this Python exception text\n    raise RuntimeError(f\"filter input invalid: {value!r}\") from e","preventionTips":["Validate inputs inside every Python filter function","Test filters in Python with realistic template arguments","Keep Python dependencies installed in the native runtime environment"],"tags":["python","template","minijinja","filter"],"backgroundTag":"python-filter-execution-failed","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}