google / google/or-tools

Calling RoutingModel_HasDimension with Python String causes TypeError

Open
#4,749 2 comments 1 reaction 1 assignee Claimed by @Mizux View on GitHub
Lang: Python Solver: Routing
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: 9.9.3963 (first Version of bug) up until latest (9.12.4544)
Language: Python

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

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

**What did you do?**
Run this test:
```python
from ortools.constraint_solver.pywrapcp import RoutingIndexManager
from ortools.constraint_solver.pywrapcp import RoutingModel

depot = 0
n_vehicles = 3
n_stops = 10

end_locations = [depot] * n_vehicles
start_locations = [depot] * n_vehicles

index_manager = RoutingIndexManager(n_stops, n_vehicles, start_locations, end_locations)
routing_model = RoutingModel(index_manager)

def callback(ix: int, iy: int) -> int:
return 1

routing_model.RegisterTransitCallback(callback)

index_manager.GetNumberOfIndices()
index_manager.GetNumberOfNodes()

assert routing_model.HasDimension(dimension_name="test") is False
```

**What did you expect to see**
Successful exit

**What did you see instead?**
```
self = >
dimension_name = 'test'

def HasDimension(self, dimension_name):
r""" Returns true if a dimension exists for a given dimension name."""
> return _pywrapcp.RoutingModel_HasDimension(self, dimension_name)
E TypeError: in method 'RoutingModel_HasDimension', argument 2 of type 'absl::string_view'

../../venv/lib/python3.8/site-packages/ortools/constraint_solver/pywrapcp.py:4826: TypeError
```

**Anything else we should know about your project / environment**
The cause of the bug is the change from string to `absl::string_view` in `HasDimension`.

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.