Skip to content

Commit 06f3589

Browse files
author
James William Pye
committed
Check for the producer_fault during CopyFail.
1 parent 4b49657 commit 06f3589

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

postgresql/copyman.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,13 +520,12 @@ def __exit__(self, typ, val, tb):
520520
if typ is None or issubclass(typ, Exception):
521521
db = self.statement.database
522522
if not db.closed and self._chunks._xact is not None:
523+
# The COPY transaction is still happening,
524+
# force an interrupt if the connection still exists.
523525
db.interrupt()
524526
if db.pq.xact:
525-
try:
526-
db._pq_complete()
527-
except Exception:
528-
# Let the copy manager indicate the failure.
529-
pass
527+
# Raise, CopyManager should trap.
528+
db._pq_complete()
530529
super().__exit__(typ, val, tb)
531530

532531
class NullReceiver(Receiver):
@@ -724,9 +723,9 @@ def __exit__(self, typ, val, tb):
724723
pass
725724

726725
self.producer.__exit__(typ, val, tb)
727-
except Exception as profail:
726+
except Exception as x:
728727
# reference profail later.
729-
pass
728+
profail = x
730729

731730
# No receivers? It wasn't a success.
732731
if not self.receivers:

postgresql/test/test_copyman.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from ..temporal import pg_tmp
99
# The asyncs, and alternative termination.
1010
from ..protocol.element3 import Notice, Notify, Error, cat_messages
11+
from .. import exceptions as pg_exc
1112

1213
# state manager can handle empty data messages, right? =)
1314
emptysource = """
@@ -530,6 +531,7 @@ def testProducerFailure(self):
530531
except copyman.CopyFail as cf:
531532
# Expecting to see CopyFail
532533
self.failUnless(True)
534+
self.failUnless(isinstance(cf.producer_fault, pg_exc.ConnectionFailureError))
533535
self.failUnless(done)
534536
self.failUnlessRaises(Exception, sqlexec, 'select 1')
535537
self.failUnlessEqual(dst.prepare(dstcount).first(), 0)

0 commit comments

Comments
 (0)