Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def commit(self, retry=None, timeout=None):
self._id = None
return None
else:
self.begin()
self.begin(retry=retry, timeout=timeout)

kwargs = _make_retry_timeout_kwargs(retry, timeout)

Expand Down
28 changes: 26 additions & 2 deletions packages/google-cloud-datastore/tests/unit/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,28 @@ def test_transaction_put_w_begin_later(database_id):
assert xact._status == xact._INITIAL


@pytest.mark.parametrize("database_id", [None, "somedb"])
def test_transaction_commit_w_begin_later_w_retry_w_timeout(database_id):
"""
If commit has to begin the transaction, it should use the same retry and timeout
"""
project = "PROJECT"
id_ = 943243
retry = mock.Mock()
timeout = 100000
ds_api = _make_datastore_api(xact_id=id_)
client = _Client(project, datastore_api=ds_api, database=database_id)
xact = _make_transaction(client, begin_later=True)
xact._status = xact._INITIAL
xact.put(_Entity(database=database_id))

xact.commit(retry=retry, timeout=timeout)

ds_api.begin_transaction.assert_called_once_with(
request=mock.ANY, retry=retry, timeout=timeout
)


@pytest.mark.parametrize("database_id", [None, "somedb"])
def test_transaction_delete_w_begin_later(database_id):
"""
Expand Down Expand Up @@ -562,9 +584,11 @@ def test_transaction_commit_no_begin(database_id):
xact.put(entity)
assert xact._status == xact._INITIAL
with mock.patch.object(xact, "begin") as begin:
begin.side_effect = lambda: setattr(xact, "_status", xact._IN_PROGRESS)
begin.side_effect = lambda **kwargs: setattr(
xact, "_status", xact._IN_PROGRESS
)
xact.commit()
begin.assert_called_once_with()
begin.assert_called_once_with(retry=None, timeout=None)


@pytest.mark.parametrize("database_id", [None, "somedb"])
Expand Down
Loading