Skip to content

Commit b369760

Browse files
committed
Merge branch '4.3' into testkit-dns-message
2 parents 51d6430 + aeaf7a7 commit b369760

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

docs/source/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ The Official Neo4j Driver for Python.
66

77
Neo4j versions supported:
88

9-
* Neo4j 4.1
10-
* Neo4j 4.0
9+
* Neo4j 4.3
10+
* Neo4j 4.2
1111
* Neo4j 3.5
1212

1313
Python versions supported:
@@ -241,4 +241,4 @@ Other Information
241241
.. _`Example Project`: https://github.com/neo4j-examples/movies-python-bolt
242242
.. _`Driver Wiki`: https://github.com/neo4j/neo4j-python-driver/wiki
243243
.. _`Migration Guide - Upgrade Neo4j drivers`: https://neo4j.com/docs/migration-guide/4.0/upgrade-driver/
244-
.. _`Neo4j Aura`: https://neo4j.com/neo4j-aura/
244+
.. _`Neo4j Aura`: https://neo4j.com/neo4j-aura/

neo4j/io/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
)
8989
from neo4j.routing import RoutingTable
9090

91+
9192
# Set up logger
9293
log = getLogger("neo4j")
9394

@@ -250,9 +251,8 @@ def open(cls, address, *, auth=None, timeout=None, routing_context=None, **pool_
250251

251252
try:
252253
connection.hello()
253-
except Exception as error:
254-
log.debug("[#%04X] C: <CLOSE> %s", s.getsockname()[1], str(error))
255-
_close_socket(s)
254+
except Exception:
255+
connection.close()
256256
raise
257257

258258
return connection

neo4j/time/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ def __repr__(self):
389389
def __str__(self):
390390
return self.iso_format()
391391

392+
def __copy__(self):
393+
return self.__new(self.ticks, self.hour, self.minute, self.second, self.tzinfo)
394+
395+
def __deepcopy__(self, memodict={}):
396+
return self.__copy__()
397+
392398
@classmethod
393399
def from_iso_format(cls, s):
394400
m = DURATION_ISO_PATTERN.match(s)
@@ -845,6 +851,12 @@ def __sub__(self, other):
845851
except TypeError:
846852
return NotImplemented
847853

854+
def __copy__(self):
855+
return self.__new(self.__ordinal, self.__year, self.__month, self.__day)
856+
857+
def __deepcopy__(self, *args, **kwargs):
858+
return self.__copy__()
859+
848860
# INSTANCE METHODS #
849861

850862
def replace(self, **kwargs):
@@ -1133,6 +1145,12 @@ def __add__(self, other):
11331145
def __sub__(self, other):
11341146
return NotImplemented
11351147

1148+
def __copy__(self):
1149+
return self.__new(self.__ticks, self.__hour, self.__minute, self.__second, self.__tzinfo)
1150+
1151+
def __deepcopy__(self, *args, **kwargs):
1152+
return self.__copy__()
1153+
11361154
# INSTANCE METHODS #
11371155

11381156
def replace(self, **kwargs):
@@ -1474,6 +1492,12 @@ def __sub__(self, other):
14741492
return self.__add__(-other)
14751493
return NotImplemented
14761494

1495+
def __copy__(self):
1496+
return self.combine(self.__date, self.__time)
1497+
1498+
def __deepcopy__(self, *args, **kwargs):
1499+
return self.__copy__()
1500+
14771501
# INSTANCE METHODS #
14781502

14791503
def date(self):

neo4j/work/simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
sleep,
2727
)
2828

29-
from neo4j.conf import SessionConfig
3029
from neo4j.api import (
3130
READ_ACCESS,
3231
WRITE_ACCESS,
3332
)
33+
from neo4j.conf import SessionConfig
3434
from neo4j.data import DataHydrator
3535
from neo4j.exceptions import (
3636
ClientError,
@@ -337,7 +337,7 @@ def _run_transaction(self, access_mode, transaction_function, *args, **kwargs):
337337
try:
338338
result = transaction_function(tx, *args, **kwargs)
339339
except Exception:
340-
tx.rollback()
340+
tx.close()
341341
raise
342342
else:
343343
tx.commit()

neo4j/work/transaction.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def commit(self):
139139
if self._closed:
140140
raise TransactionError("Transaction closed")
141141
metadata = {}
142-
self._consume_results() # DISCARD pending records then do a commit.
143142
try:
143+
self._consume_results() # DISCARD pending records then do a commit.
144144
self._connection.commit(on_success=metadata.update)
145145
self._connection.send_all()
146146
self._connection.fetch_all()
@@ -159,18 +159,19 @@ def rollback(self):
159159
if self._closed:
160160
raise TransactionError("Transaction closed")
161161
metadata = {}
162-
if not self._connection._is_reset:
163-
self._consume_results() # DISCARD pending records then do a rollback.
164-
self._connection.rollback(on_success=metadata.update)
165-
self._connection.send_all()
166-
self._connection.fetch_all()
167-
self._closed = True
168-
self._on_closed()
162+
try:
163+
if not self._connection._is_reset:
164+
# DISCARD pending records then do a rollback.
165+
self._consume_results()
166+
self._connection.rollback(on_success=metadata.update)
167+
self._connection.send_all()
168+
self._connection.fetch_all()
169+
finally:
170+
self._closed = True
171+
self._on_closed()
169172

170173
def close(self):
171174
"""Close this transaction, triggering a ROLLBACK if not closed.
172-
173-
:raise TransactionError: if the transaction could not perform a ROLLBACK.
174175
"""
175176
if self._closed:
176177
return

tests/unit/time/test_date.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from unittest import TestCase
2525

2626
import pytz
27+
import copy
2728

2829
from neo4j.time import Duration, Date, UnixEpoch, ZeroDate
2930

@@ -532,3 +533,15 @@ def test_from_iso_format(self):
532533
expected = Date(2018, 10, 1)
533534
actual = Date.from_iso_format("2018-10-01")
534535
self.assertEqual(expected, actual)
536+
537+
def test_date_copy(self):
538+
d = Date(2010, 10, 1)
539+
d2 = copy.copy(d)
540+
self.assertIsNot(d, d2)
541+
self.assertEqual(d, d2)
542+
543+
def test_date_deep_copy(self):
544+
d = Date(2010, 10, 1)
545+
d2 = copy.deepcopy(d)
546+
self.assertIsNot(d, d2)
547+
self.assertEqual(d, d2)

tests/unit/time/test_datetime.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
21+
import copy
2222
from unittest import TestCase
2323
from datetime import (
2424
datetime,
@@ -337,6 +337,18 @@ def test_from_iso_format_with_negative_long_tz(self):
337337
actual = DateTime.from_iso_format("2018-10-01T12:34:56.123456789-12:34:56.123456")
338338
self.assertEqual(expected, actual)
339339

340+
def test_datetime_copy(self):
341+
d = DateTime(2010, 10, 1, 10, 0, 10)
342+
d2 = copy.copy(d)
343+
self.assertIsNot(d, d2)
344+
self.assertEqual(d, d2)
345+
346+
def test_datetime_deep_copy(self):
347+
d = DateTime(2010, 10, 1, 10, 0, 12)
348+
d2 = copy.deepcopy(d)
349+
self.assertIsNot(d, d2)
350+
self.assertEqual(d, d2)
351+
340352

341353
def test_iso_format_with_time_zone_case_1():
342354
# python -m pytest tests/unit/time/test_datetime.py -s -v -k test_iso_format_with_time_zone_case_1

0 commit comments

Comments
 (0)