Skip to content

Commit ac99919

Browse files
authored
Merge pull request #35 from marklogic/feature/tx-tweak
Improved error for when transaction cannot be completed
2 parents 9698e3c + 49b9d8a commit ac99919

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

marklogic/transactions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
from requests import Response, Session
3+
from requests.exceptions import HTTPError
34

45
logger = logging.getLogger(__name__)
56

@@ -71,9 +72,10 @@ def __exit__(self, *args):
7172
if len(args) > 1 and isinstance(args[1], Exception)
7273
else self.commit()
7374
)
74-
assert (
75-
204 == response.status_code
76-
), f"Could not end transaction; cause: {response.text}"
75+
# raise_for_status() is not used here as it results in an error without any
76+
# context of what went wrong.
77+
if response.status_code != 204:
78+
raise HTTPError(f"Could not end transaction; cause: {response.text}")
7779

7880

7981
class TransactionManager:

tests/test_transactions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
from marklogic import Client
44
from marklogic.documents import Document
5+
from requests.exceptions import HTTPError
56

67
PERMS = {"python-tester": ["read", "update"]}
78

@@ -65,7 +66,7 @@ def test_time_limit(client: Client):
6566
doc1 = Document("/t1.json", {}, permissions=PERMS)
6667
client.documents.write(doc1, tx=tx)
6768

68-
except AssertionError as error:
69+
except HTTPError as error:
6970
assert error.args[0].startswith("Could not end transaction")
7071
assert "No transaction with identifier" in error.args[0]
7172
assert "XDMP-NOTXN" in error.args[0]

0 commit comments

Comments
 (0)