Skip to content

Commit 9e270ef

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 0cfd03a commit 9e270ef

2 files changed

Lines changed: 59 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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
8+
from ravendb.documents.operations.counters import (
9+
CounterBatch,
10+
CounterBatchOperation,
11+
CounterOperation,
12+
CounterOperationType,
13+
DocumentCountersOperation,
14+
)
15+
from ravendb.infrastructure.entities import User
16+
from ravendb.tests.test_base import TestBase
17+
18+
19+
class TestRavenDB22150(TestBase):
20+
def setUp(self):
21+
super().setUp()
22+
23+
def test_increment_without_delta_defaults_to_one(self):
24+
"""
25+
CounterOperation(INCREMENT) with no delta argument defaults to delta=1
26+
on the client, matching the C# client's permissive default.
27+
28+
C# spec: IncrementByDefaultValue — sends a batch with two operations:
29+
one with an explicit delta and one with no delta. The no-delta
30+
operation should increment by 1.
31+
"""
32+
with self.store.open_session() as session:
33+
session.store(User(name="Danielle"), "users/1")
34+
session.save_changes()
35+
36+
with self.store.open_session() as session:
37+
session.counters_for("users/1").increment("likes", 10)
38+
session.counters_for("users/1").increment("dislikes", 20)
39+
session.save_changes()
40+
41+
# Single batch: explicit delta=5 for likes, no delta for dislikes (defaults to 1).
42+
result = self.store.operations.send(
43+
CounterBatchOperation(
44+
CounterBatch(
45+
documents=[
46+
DocumentCountersOperation(
47+
document_id="users/1",
48+
operations=[
49+
CounterOperation("likes", CounterOperationType.INCREMENT, delta=5),
50+
CounterOperation("dislikes", CounterOperationType.INCREMENT),
51+
],
52+
)
53+
]
54+
)
55+
)
56+
)
57+
58+
self.assertEqual(21, result.counters[1].total_value)

0 commit comments

Comments
 (0)