|
34 | 34 | from neo4j.exceptions import (
|
35 | 35 | ConfigurationError,
|
36 | 36 | DatabaseUnavailable,
|
37 |
| - DriverError, |
38 | 37 | ForbiddenOnReadOnlyDatabase,
|
39 | 38 | Neo4jError,
|
40 | 39 | NotALeader,
|
|
48 | 47 | CommitResponse,
|
49 | 48 | InitResponse,
|
50 | 49 | Response,
|
| 50 | + tx_timeout_as_ms, |
51 | 51 | )
|
52 | 52 | from neo4j.io._bolt3 import (
|
53 | 53 | ServerStateManager,
|
@@ -178,11 +178,8 @@ def run(self, query, parameters=None, mode=None, bookmarks=None,
|
178 | 178 | extra["tx_metadata"] = dict(metadata)
|
179 | 179 | except TypeError:
|
180 | 180 | raise TypeError("Metadata must be coercible to a dict")
|
181 |
| - if timeout: |
182 |
| - try: |
183 |
| - extra["tx_timeout"] = int(1000 * timeout) |
184 |
| - except TypeError: |
185 |
| - raise TypeError("Timeout must be specified as a number of seconds") |
| 181 | + if timeout or (isinstance(timeout, (float, int)) and timeout == 0): |
| 182 | + extra["tx_timeout"] = tx_timeout_as_ms(timeout) |
186 | 183 | fields = (query, parameters, extra)
|
187 | 184 | log.debug("[#%04X] C: RUN %s", self.local_port, " ".join(map(repr, fields)))
|
188 | 185 | if query.upper() == u"COMMIT":
|
@@ -229,11 +226,8 @@ def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None,
|
229 | 226 | extra["tx_metadata"] = dict(metadata)
|
230 | 227 | except TypeError:
|
231 | 228 | raise TypeError("Metadata must be coercible to a dict")
|
232 |
| - if timeout: |
233 |
| - try: |
234 |
| - extra["tx_timeout"] = int(1000 * timeout) |
235 |
| - except TypeError: |
236 |
| - raise TypeError("Timeout must be specified as a number of seconds") |
| 229 | + if timeout or (isinstance(timeout, (float, int)) and timeout == 0): |
| 230 | + extra["tx_timeout"] = tx_timeout_as_ms(timeout) |
237 | 231 | log.debug("[#%04X] C: BEGIN %r", self.local_port, extra)
|
238 | 232 | self._append(b"\x11", (extra,), Response(self, "begin", **handlers))
|
239 | 233 |
|
@@ -490,12 +484,8 @@ def run(self, query, parameters=None, mode=None, bookmarks=None,
|
490 | 484 | extra["tx_metadata"] = dict(metadata)
|
491 | 485 | except TypeError:
|
492 | 486 | raise TypeError("Metadata must be coercible to a dict")
|
493 |
| - if timeout: |
494 |
| - try: |
495 |
| - extra["tx_timeout"] = int(1000 * timeout) |
496 |
| - except TypeError: |
497 |
| - raise TypeError("Timeout must be specified as a number of " |
498 |
| - "seconds") |
| 487 | + if timeout or (isinstance(timeout, (float, int)) and timeout == 0): |
| 488 | + extra["tx_timeout"] = tx_timeout_as_ms(timeout) |
499 | 489 | fields = (query, parameters, extra)
|
500 | 490 | log.debug("[#%04X] C: RUN %s", self.local_port,
|
501 | 491 | " ".join(map(repr, fields)))
|
@@ -525,11 +515,7 @@ def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None,
|
525 | 515 | extra["tx_metadata"] = dict(metadata)
|
526 | 516 | except TypeError:
|
527 | 517 | raise TypeError("Metadata must be coercible to a dict")
|
528 |
| - if timeout: |
529 |
| - try: |
530 |
| - extra["tx_timeout"] = int(1000 * timeout) |
531 |
| - except TypeError: |
532 |
| - raise TypeError("Timeout must be specified as a number of " |
533 |
| - "seconds") |
| 518 | + if timeout or (isinstance(timeout, (float, int)) and timeout == 0): |
| 519 | + extra["tx_timeout"] = tx_timeout_as_ms(timeout) |
534 | 520 | log.debug("[#%04X] C: BEGIN %r", self.local_port, extra)
|
535 | 521 | self._append(b"\x11", (extra,), Response(self, "begin", **handlers))
|
0 commit comments