Skip to content

Commit 72daa2d

Browse files
committed
RDBC-1031: default delta=1 when CounterOperation.INCREMENT delta is omitted
C# CounterOperation for INCREMENT defaults delta to 1 when not provided. Python was raising ValueError instead. Fix assigns delta=1 on the client when delta is None, matching the C# client's permissive default. Regression test: test_counter_increment_default_delta.py verifies that omitting delta results in total=21 after two increments (explicit 20 + implicit 1).
1 parent 4cd66c4 commit 72daa2d

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

ravendb/documents/operations/counters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
if not counter_operation_type:
3636
raise ValueError(f"Missing counter_operation_type property in counter {counter_name}")
3737
if delta is None and counter_operation_type == CounterOperationType.INCREMENT:
38-
raise ValueError(f"Missing delta property in counter {counter_name} of type {counter_operation_type}")
38+
delta = 1
3939
self.counter_name = counter_name
4040
self.delta = delta
4141
self.counter_operation_type = counter_operation_type
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""
2+
Counter increment: omitting delta when incrementing defaults to delta=1.
3+
4+
C# reference: SlowTests.Issues/Issues/RavenDB_22150.cs
5+
IncrementByDefaultValue
6+
"""
7+
from ravendb.documents.operations.counters import (
8+
CounterBatch,
9+
CounterBatchOperation,
10+
CounterOperation,
11+
CounterOperationType,
12+
DocumentCountersOperation,
13+
)
14+
from ravendb.infrastructure.entities import User
15+
from ravendb.tests.test_base import TestBase
16+
17+
18+
class TestRavenDB22150(TestBase):
19+
def setUp(self):
20+
super().setUp()
21+
22+
def test_increment_without_delta_defaults_to_one(self):
23+
"""
24+
CounterOperation(INCREMENT) with no delta argument defaults to delta=1
25+
on the client, matching the C# client's permissive default.
26+
27+
C# spec: IncrementByDefaultValue — sends a batch with two operations:
28+
one with an explicit delta and one with no delta. The no-delta
29+
operation should increment by 1.
30+
"""
31+
with self.store.open_session() as session:
32+
session.store(User(name="Danielle"), "users/1")
33+
session.save_changes()
34+
35+
with self.store.open_session() as session:
36+
session.counters_for("users/1").increment("likes", 10)
37+
session.counters_for("users/1").increment("dislikes", 20)
38+
session.save_changes()
39+
40+
# Single batch: explicit delta=5 for likes, no delta for dislikes (defaults to 1).
41+
result = self.store.operations.send(
42+
CounterBatchOperation(
43+
CounterBatch(
44+
documents=[
45+
DocumentCountersOperation(
46+
document_id="users/1",
47+
operations=[
48+
CounterOperation("likes", CounterOperationType.INCREMENT, delta=5),
49+
CounterOperation("dislikes", CounterOperationType.INCREMENT),
50+
],
51+
)
52+
]
53+
)
54+
)
55+
)
56+
57+
self.assertEqual(21, result.counters[1].total_value)

0 commit comments

Comments
 (0)