google / google/or-tools

Broken usage of pybind11 "keep_alive" annotation

Open
#5,140 3 comments 0 reactions 1 assignee Claimed by @Mizux View on GitHub
Dependencies Lang: Python Solver: CP-SAT Solver
Dominant language
C++
Stars
14.1k
Forks
2.5k
Avg merge
8h 39m
Merged PRs (30d)
72

Description

**What version of OR-Tools and what language are you using?**
Version: main/v9.15
Language: Python

**Which solver are you using (e.g. CP-SAT, Routing Solver, GLOP, BOP, Gurobi)**
n/a

**What operating system (Linux, Windows, ...) and version?**

**What did you do?**
Compile it

**What did you expect to see**
no errors

**What did you see instead?**
```
[ 762s] 2870 | .def_property_readonly(
[ 762s] | ~~~~~~~~~~~~~~~~~~~~~~^
[ 762s] 2871 | "tails",
[ 762s] | ~~~~~~~~
[ 762s] 2872 | [](operations_research::sat::CircuitConstraintProto* self) { return self->mutable_tails(); },
[ 762s] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 762s] 2873 | py::return_value_policy::reference, py::keep_alive<0, 1>())
[ 762s] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ 762s] /usr/include/pybind11/pybind11.h:2659:25: error: static assertion failed: def_property family does not currently support keep_alive. Use a py::cpp_function instead.
```

While this error message is specific to current pybind11 versions, the actual error is inside the or-tools code, and the generated code is also wrong with the bundled pybind11.

For details, see https://github.com/pybind/pybind11/pull/5533

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.