Skip to content

Commit e666b27

Browse files
committed
raises ProtcolError if trying to run/begin_transaction when a transaction is open
1 parent e5f235e commit e666b27

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

neo4j/v1/session.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class which can be used to obtain `Driver` instances that are used for
2525
managing sessions.
2626
"""
2727

28-
2928
from __future__ import division
3029

3130
from collections import deque, namedtuple
@@ -34,10 +33,9 @@ class which can be used to obtain `Driver` instances that are used for
3433
from .compat import integer, string, urlparse
3534
from .connection import connect, Response, RUN, PULL_ALL
3635
from .constants import ENCRYPTED_DEFAULT, TRUST_DEFAULT, TRUST_SIGNED_CERTIFICATES
37-
from .exceptions import CypherError
36+
from .exceptions import CypherError, ProtocolError
3837
from .types import hydrated
3938

40-
4139
DEFAULT_MAX_POOL_SIZE = 50
4240

4341
STATEMENT_TYPE_READ_ONLY = "r"
@@ -352,7 +350,6 @@ def contains_updates(self):
352350
#: a list of sub-plans
353351
Plan = namedtuple("Plan", ("operator_type", "identifiers", "arguments", "children"))
354352

355-
356353
#: A profiled plan describes how the database executed your statement.
357354
#:
358355
#: db_hits:
@@ -440,6 +437,9 @@ def run(self, statement, parameters=None):
440437
:return: Cypher result
441438
:rtype: :class:`.StatementResult`
442439
"""
440+
if self.transaction:
441+
raise ProtocolError("Please close the currently open transaction object before running more "
442+
"statements/transactions in the current session.")
443443

444444
# Ensure the statement is a Unicode value
445445
if isinstance(statement, bytes):
@@ -480,7 +480,9 @@ def begin_transaction(self):
480480
481481
:return: new :class:`.Transaction` instance.
482482
"""
483-
assert not self.transaction
483+
if self.transaction:
484+
raise ProtocolError("Please close the currently open transaction object before running more "
485+
"statements/transactions in the current session.")
484486
self.transaction = Transaction(self)
485487
return self.transaction
486488

test/tck/steps/errror_reporting_steps.py

Whitespace-only changes.

0 commit comments

Comments
 (0)