mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
fix(python): reject Expr inputs on unregistered Function definitions (#5125)
`FunctionDefinition.__call__` ran the decorated Python callable with any
value it was given, so `my_function(value=col("value"))` executed user
code against an `Expr` or silently returned one, with errors such as
`float() argument must be a string or a real number, not 'Expr'`. A
column reference is not a local value: it binds only on a registered
`FunctionVersion`.
An unregistered definition now rejects `Expr` positional and keyword
arguments with `TypeError` before the callable runs, and names the
supported path: `create_function`/`create_function_async`, then
`col(...)` on the returned version. Plain Python and Arrow arguments,
and the class `__init__`/`__call__` lifecycle, are unchanged.
The Function authoring guide's batch example did not register either: a
`pyarrow.Array` annotation carries no element types, so `score_batch`
raised `TypeError` for missing `input_schema` and `output_schema`, and
the page claimed one `pa.RecordBatch` parameter could read several
columns. The example now passes both schemas, shows one `pa.Array`
parameter per input column for multi-column functions, and states that
`input_schema` matches parameters one to one, so a `RecordBatch`
parameter binds one input column. The GPU class example on the same page
had the same missing-schema defect and is fixed too.
Compatibility: code that passed `col(...)` to an unregistered definition
now gets `TypeError` instead of running user code against an `Expr`.
That call was never a supported binding and produced no usable result;
no supported call changes.
This commit is contained in:
@@ -449,7 +449,9 @@ and then call the returned instance; call `close()` if the class defines it. Thi
|
||||
path uses the current Python environment and does not create a registered
|
||||
`FunctionVersion`, build the declared remote runtime, resolve Secrets, or execute
|
||||
the remote Arrow adapter. A registered `FunctionVersion` call instead binds
|
||||
`col(...)` inputs and returns a remote `FunctionApplication`.
|
||||
`col(...)` inputs and returns a remote `FunctionApplication`. Passing an `Expr`
|
||||
such as `col("value")` to a definition raises `TypeError` before the callable
|
||||
runs; bind it on the registered `FunctionVersion` instead.
|
||||
|
||||
```python
|
||||
from lancedb import function
|
||||
|
||||
Reference in New Issue
Block a user