GumpacG opened a new pull request, #3531:
URL: https://github.com/apache/tinkerpop/pull/3531
# Fix gremlin-go PartitionStrategy panic and gremlin-python
ProductiveByStrategy productiveKeys
## 1. gremlin-go: `PartitionStrategy` panics when `ReadPartitions` is unset
File: `gremlin-go/driver/strategies.go`
`PartitionStrategy` called `config.ReadPartitions.ToSlice()` with no nil
check. `ReadPartitions` is a `Set` interface, so leaving it unset (a valid,
documented configuration - "zeroed values are ignored") caused a nil-interface
method call and crashed the caller.
### Use case
Configure a write-only partition (write to partition `a`, read from
everywhere), leaving `ReadPartitions` unset:
```go
g =
g.WithStrategies(gremlingo.PartitionStrategy(gremlingo.PartitionStrategyConfig{
PartitionKey: "_partition",
WritePartition: "a",
// ReadPartitions intentionally not set
}))
```
### Behaviour
| | Result |
|---|---|
| Before | Panics at strategy construction: `runtime error: invalid memory
address or nil pointer dereference` |
| After | Constructs normally; `readPartitions` is simply omitted from the
configuration when unset |
## 2. gremlin-python: `ProductiveByStrategy` drops `productiveKeys`
File: `gremlin-python/src/main/python/gremlin_python/process/strategies.py`
`ProductiveByStrategy.__init__` accepted a `productiveKeys` argument but
never stored it in `self.configuration`, so it was silently discarded before
the request was built. The strategy was therefore always sent with no keys (the
empty singleton), and the caller's `productiveKeys` had no effect. Every other
GLV (Java, Go, JavaScript, .NET) carries `productiveKeys` correctly, so
gremlin-python was the lone outlier.
### Use case
Scope the strategy to specific keys:
```python
g = traversal().withStrategies(ProductiveByStrategy(productiveKeys=["name",
"age"]))
```
### Behaviour
| | Result |
|---|---|
| Before | `productiveKeys` is ignored; the strategy serializes as the bare
`ProductiveByStrategy` singleton (empty configuration), so `by()`-modulation
productivity does not match what was configured and differs from every other
driver |
| After | `productiveKeys` is carried in the configuration
(`{"productiveKeys": ["name", "age"]}`) and serialized to the server, matching
the other GLVs |
## Tests
- `gremlin-go/driver/strategies_test.go`: `PartitionStrategy` with
`ReadPartitions` unset no longer panics and produces the expected configuration.
- `gremlin-python/.../tests/unit/process/test_strategies.py`
(`test_configurable`): `ProductiveByStrategy(productiveKeys=[...])` stores the
keys in its configuration, and `ProductiveByStrategy()` yields an empty
configuration.
Assisted-by: Kiro: Claude Opus 4.8
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]