Skip to content

List macros over a null receiver raise TypeError instead of a CEL error; size(null) returns 0 #201

Open

Description

@danmelcher

cel-python 0.5.0, Python 3.13.

import celpy
env = celpy.Environment()
run = lambda e, a: env.program(env.compile(e)).evaluate(a)
run("x.exists(i, i == 1)", {"x": None})           # TypeError: 'NoneType' object is not iterable
run("false && x.exists(i, i == 1)", {"x": None})  # TypeError (expected: false)
run("size(x)", {"x": None})                       # 0 (expected: no such overload)

Per the CEL spec, applying a macro or size to null is an evaluation error ("no such overload"), and errors are absorbed by &&/|| (so false && <error> is false). Today the macro case escapes as a Python exception, so the whole expression fails even where a logical operator should settle it. #75 fixed the related case of a missing field (a CELEvalError receiver); an explicit null receiver still reaches the iteration in Evaluator.member_dot_arg.

A possible fix: in member_dot_arg, return a CELEvalError ("no such overload") when the receiver is not a list or map, as is already done when it is a CELEvalError; and have size raise the same for null.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions