cube-js/cube · error · minijinja::Error

Unable to call method on Py<Function>

Error message

Unable to call method on Py<Function>

What it means

A sentinel guard for JinjaPythonFunction: calling a method on a Python function object (e.g. {{ myfunc.upper }}) is unsupported. Python functions exposed to templates can only be invoked directly via call — attribute/method dispatch on them is deliberately rejected rather than delegated to Python.

Source

Thrown at packages/cubejs-backend-native/src/template/mj_value/python.rs:237

impl std::fmt::Display for JinjaPythonFunction {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        std::fmt::Display::fmt(&self.inner, f)
    }
}

impl Object for JinjaPythonFunction {
    fn kind(&self) -> ObjectKind<'_> {
        ObjectKind::Plain
    }

    fn call_method(
        &self,
        _state: &mj::State,
        _name: &str,
        _args: &[Value],
    ) -> Result<Value, mj::Error> {
        Err(mj::Error::new(
            minijinja::ErrorKind::InvalidOperation,
            "Unable to call method on Py<Function>",
        ))
    }

    fn call(&self, _state: &mj::State, args: &[Value]) -> Result<Value, mj::Error> {
        let mut arguments = Vec::with_capacity(args.len());

        for arg in args {
            arguments.push(from_minijinja_value(arg)?);
        }

        let py_runtime = py_runtime().map_err(|err| {
            mj::Error::new(
                mj::ErrorKind::EvalBlock,
                format!("Python runtime error: {}", err),
            )
        })?;

View on GitHub (pinned to 7d981676b3)

Solutions

  1. Invoke the exposed Python function directly, e.g. {{ myfunc(arg) }}, instead of calling methods on it
  2. Expose a Python object with methods if per-method dispatch is needed
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/cubejs-backend-native/src/template/mj_value/python.rs:237 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of cube-js/cube@7d981676b3 (2026-09-02). Data as JSON: /api/errors/3f0b69fb94d2527e. Report an issue: GitHub.