Skip to content

Commit 7a23ad7

Browse files
committed
Fix WaitFor replication/index settings silently ignored after SaveChanges
Setting explicit replication timeouts, throw-on-timeout behavior, or specific index names through the WaitFor builders had no effect. The user's values were written to wrong fields (copy-paste from adjacent builders), while the actual fields stayed None and got filled with convention defaults. A 5-second explicit timeout became 15 seconds. Calling with no arguments crashed due to a stale None reference.
1 parent bbd54cb commit 7a23ad7

3 files changed

Lines changed: 74 additions & 4 deletions

File tree

ravendb/documents/session/document_session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,8 @@ def wait_for_replication_after_save_changes(
828828
builder_options = builder.get_options()
829829
replication_options = builder_options.replication_options
830830
if replication_options is None:
831-
builder_options.replication_options = ReplicationBatchOptions()
831+
replication_options = ReplicationBatchOptions()
832+
builder_options.replication_options = replication_options
832833

833834
if replication_options.wait_for_replicas_timeout is None:
834835
replication_options.wait_for_replicas_timeout = (

ravendb/documents/session/document_session_operations/in_memory_document_session_operations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,7 @@ def get_options(self) -> BatchOptions:
18571857
def with_timeout(
18581858
self, timeout: datetime.timedelta
18591859
) -> InMemoryDocumentSessionOperations.ReplicationWaitOptsBuilder:
1860-
self.get_options().replication_options.wait_for_indexes_timeout = timeout
1860+
self.get_options().replication_options.wait_for_replicas_timeout = timeout
18611861
return self
18621862

18631863
def throw_on_timeout(self, should_throw: bool) -> InMemoryDocumentSessionOperations.ReplicationWaitOptsBuilder:
@@ -1890,11 +1890,11 @@ def with_timeout(self, timeout: datetime.timedelta) -> InMemoryDocumentSessionOp
18901890
return self
18911891

18921892
def throw_on_timeout(self, should_throw: bool) -> InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder:
1893-
self.get_options().index_options.throw_on_timeout_in_wait_for_replicas = should_throw
1893+
self.get_options().index_options.throw_on_timeout_in_wait_for_indexes = should_throw
18941894
return self
18951895

18961896
def wait_for_indexes(self, *indexes: str) -> InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder:
1897-
self.get_options().index_options.wait_for_indexes = indexes
1897+
self.get_options().index_options.wait_for_specific_indexes = indexes
18981898
return self
18991899

19001900
class SaveChangesData:

ravendb/tests/session_tests/test_advanced.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ravendb.documents.operations.indexes import PutIndexesOperation
44
from ravendb.tests.test_base import TestBase
55
from ravendb.exceptions.exceptions import InvalidOperationException
6+
import datetime
67
import unittest
78
import pathlib
89
import os
@@ -126,6 +127,74 @@ def test_try_delete_attachment_putted_in_the_same_session(self):
126127
with self.assertRaises(InvalidOperationException):
127128
session.advanced.attachments.delete("users/1-A", "my_text_file")
128129

130+
def test_wait_for_replication_timeout_propagates(self):
131+
with self.store.open_session() as session:
132+
session.store(User("Idan", 30), "users/1-A")
133+
session.advanced.wait_for_replication_after_save_changes(
134+
lambda opts: opts.with_timeout(datetime.timedelta(seconds=5))
135+
)
136+
batch_options = session._save_changes_options
137+
self.assertIsNotNone(batch_options)
138+
self.assertIsNotNone(batch_options.replication_options)
139+
self.assertEqual(batch_options.replication_options.wait_for_replicas_timeout, datetime.timedelta(seconds=5))
140+
141+
def test_wait_for_indexes_throw_on_timeout_propagates(self):
142+
with self.store.open_session() as session:
143+
session.store(User("Idan", 30), "users/1-A")
144+
session.advanced.wait_for_indexes_after_save_changes(lambda opts: opts.throw_on_timeout(False))
145+
batch_options = session._save_changes_options
146+
self.assertIsNotNone(batch_options)
147+
self.assertIsNotNone(batch_options.index_options)
148+
self.assertIs(batch_options.index_options.throw_on_timeout_in_wait_for_indexes, False)
149+
150+
def test_wait_for_indexes_specific_indexes_propagates(self):
151+
with self.store.open_session() as session:
152+
session.store(User("Idan", 30), "users/1-A")
153+
session.advanced.wait_for_indexes_after_save_changes(lambda opts: opts.wait_for_indexes("MyIndex"))
154+
batch_options = session._save_changes_options
155+
self.assertIsNotNone(batch_options)
156+
self.assertIsNotNone(batch_options.index_options)
157+
self.assertIn("MyIndex", batch_options.index_options.wait_for_specific_indexes)
158+
159+
160+
class _FakeSession:
161+
def __init__(self):
162+
self._save_changes_options = None
163+
164+
165+
class TestWaitForOptions(unittest.TestCase):
166+
def test_replication_timeout_propagates(self):
167+
from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import (
168+
InMemoryDocumentSessionOperations,
169+
)
170+
171+
session = _FakeSession()
172+
builder = InMemoryDocumentSessionOperations.ReplicationWaitOptsBuilder(session)
173+
builder.with_timeout(datetime.timedelta(seconds=5))
174+
self.assertEqual(
175+
session._save_changes_options.replication_options.wait_for_replicas_timeout, datetime.timedelta(seconds=5)
176+
)
177+
178+
def test_indexes_throw_on_timeout_propagates(self):
179+
from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import (
180+
InMemoryDocumentSessionOperations,
181+
)
182+
183+
session = _FakeSession()
184+
builder = InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder(session)
185+
builder.throw_on_timeout(False)
186+
self.assertIs(session._save_changes_options.index_options.throw_on_timeout_in_wait_for_indexes, False)
187+
188+
def test_specific_indexes_propagates(self):
189+
from ravendb.documents.session.document_session_operations.in_memory_document_session_operations import (
190+
InMemoryDocumentSessionOperations,
191+
)
192+
193+
session = _FakeSession()
194+
builder = InMemoryDocumentSessionOperations.IndexesWaitOptsBuilder(session)
195+
builder.wait_for_indexes("MyIndex")
196+
self.assertIn("MyIndex", session._save_changes_options.index_options.wait_for_specific_indexes)
197+
129198

130199
if __name__ == "__main__":
131200
unittest.main()

0 commit comments

Comments
 (0)