Broken usage of pybind11 "keep_alive" annotation

Open
#5,140 3 comments 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 1 day

@Mizux is already working on this.

Since May 13, 2026.

  • #5145 by @KasimVali2207 — closed without merging

Assessment

This issue has not been assessed yet.

Description

Dependencies Lang: Python Solver: CP-SAT Solver

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

Dominant language
C++
Stars
14.5k
Forks
2.6k
Avg merge
9h 43m
Merged PRs (30d)
53

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google/or-tools

All issues in google/or-tools

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.