Skip to content

Commit a65adc0

Browse files
committed
nanobind: UDF kind via enum .name; TryConvert clears PyErr
1 parent d35c15c commit a65adc0

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/duckdb_py/python_udf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ struct PythonUDFData {
502502
if (DuckDBPyType::TryConvert(py::borrow<py::object>(value.attr("annotation")), pytype)) {
503503
parameters.push_back(pytype->Type());
504504
} else {
505-
std::string kind = py::cast<std::string>(py::str(value.attr("kind")));
505+
std::string kind = py::cast<std::string>(value.attr("kind").attr("name"));
506506
auto parameter_kind = ParameterKind::FromString(kind);
507507
if (parameter_kind == ParameterKind::Type::VAR_POSITIONAL) {
508508
varargs = LogicalType::ANY;

src/duckdb_py/typing/pytype.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ bool DuckDBPyType::TryConvert(const py::object &object, std::shared_ptr<DuckDBPy
340340
result = py::cast<std::shared_ptr<DuckDBPyType>>(converted);
341341
return true;
342342
} catch (...) {
343+
// A failed construction (e.g. an unannotated parameter) leaves the Python error indicator set; clear it
344+
// so the caller's subsequent Python operations don't trip on a stale error.
345+
PyErr_Clear();
343346
return false;
344347
}
345348
}

0 commit comments

Comments
 (0)