@@ -417,7 +417,7 @@ def record_io_factory(self,
417417 funpack = tuple (map (get1 , column_io ))
418418 row_constructor = self .RowTypeFactory (attribute_map = attmap , composite_relid = composite_relid )
419419
420- def raise_pack_tuple_error (procs , tup , itemnum ):
420+ def raise_pack_tuple_error (cause , procs , tup , itemnum ):
421421 data = repr (tup [itemnum ])
422422 if len (data ) > 80 :
423423 # Be sure not to fill screen with noise.
@@ -428,9 +428,9 @@ def raise_pack_tuple_error(procs, tup, itemnum):
428428 (b'M' , fmt_errmsg ('pack' , itemnum , attnames [itemnum ], typnames [itemnum ], composite_name ),),
429429 (b'W' , data ,),
430430 (b'P' , str (itemnum ),)
431- )))
431+ )), cause = cause )
432432
433- def raise_unpack_tuple_error (procs , tup , itemnum ):
433+ def raise_unpack_tuple_error (cause , procs , tup , itemnum ):
434434 data = repr (tup [itemnum ])
435435 if len (data ) > 80 :
436436 # Be sure not to fill screen with noise.
@@ -441,7 +441,7 @@ def raise_unpack_tuple_error(procs, tup, itemnum):
441441 (b'M' , fmt_errmsg ('unpack' , itemnum , attnames [itemnum ], typnames [itemnum ], composite_name ),),
442442 (b'W' , data ,),
443443 (b'P' , str (itemnum ),),
444- )))
444+ )), cause = cause )
445445
446446 def unpack_a_record (data ,
447447 unpack = io_lib .record_unpack ,
@@ -731,12 +731,13 @@ def _process_tuple_chunk_Column(self, x, range = range):
731731 r = range (len (l ))
732732 try :
733733 return [unpack (l [i ]) for i in r ]
734- except :
735- try :
736- i = next (r )
737- except StopIteration :
738- i = len (l )
739- self ._raise_column_tuple_error (self ._output_io , (l [i ],), 0 )
734+ except Exception :
735+ cause = sys .exc_info ()[1 ]
736+ try :
737+ i = next (r )
738+ except StopIteration :
739+ i = len (l )
740+ self ._raise_column_tuple_error (cause , self ._output_io , (l [i ],), 0 )
740741
741742 # Process the element.Tuple message in x for rows()
742743 def _process_tuple_chunk_Row (self , x ,
@@ -752,7 +753,7 @@ def _process_tuple_chunk_Row(self, x,
752753 def _process_tuple_chunk (self , x , proc = process_chunk ):
753754 return proc (self ._output_io , x , self ._raise_column_tuple_error )
754755
755- def _raise_column_tuple_error (self , procs , tup , itemnum ):
756+ def _raise_column_tuple_error (self , cause , procs , tup , itemnum ):
756757 'for column processing'
757758 # The element traceback will include the full list of parameters.
758759 data = repr (tup [itemnum ])
@@ -775,7 +776,7 @@ def _raise_column_tuple_error(self, procs, tup, itemnum):
775776 (b'H' , "Try casting the column to 'text'." ),
776777 (b'P' , str (itemnum )),
777778 ))
778- self .database .typio .raise_client_error (em , creator = self )
779+ self .database .typio .raise_client_error (em , creator = self , cause = cause )
779780
780781 @property
781782 def state (self ):
@@ -1302,7 +1303,7 @@ def _pq_parameters(self, parameters, proc = process_tuple):
13021303 # process_tuple failed(exception). The parameters could not be packed.
13031304 # This function is called with the given information in the context
13041305 # of the original exception(to allow chaining).
1305- def _raise_parameter_tuple_error (self , procs , tup , itemnum ):
1306+ def _raise_parameter_tuple_error (self , cause , procs , tup , itemnum ):
13061307 # Find the SQL type name. This should *not* hit the server.
13071308 typ = self .database .typio .sql_type_from_oid (
13081309 self .pg_parameter_types [itemnum ]
@@ -1325,11 +1326,11 @@ def _raise_parameter_tuple_error(self, procs, tup, itemnum):
13251326 (b'H' , "Try casting the parameter to 'text', then to the target type." ),
13261327 (b'P' , str (itemnum ))
13271328 ))
1328- self .database .typio .raise_client_error (em , creator = self )
1329+ self .database .typio .raise_client_error (em , creator = self , cause = cause )
13291330
13301331 ##
13311332 # Similar to the parameter variant.
1332- def _raise_column_tuple_error (self , procs , tup , itemnum ):
1333+ def _raise_column_tuple_error (self , cause , procs , tup , itemnum ):
13331334 # Find the SQL type name. This should *not* hit the server.
13341335 typ = self .database .typio .sql_type_from_oid (
13351336 self .pg_column_types [itemnum ]
@@ -1352,7 +1353,7 @@ def _raise_column_tuple_error(self, procs, tup, itemnum):
13521353 (b'H' , "Try casting the column to 'text'." ),
13531354 (b'P' , str (itemnum )),
13541355 ))
1355- self .database .typio .raise_client_error (em , creator = self )
1356+ self .database .typio .raise_client_error (em , creator = self , cause = cause )
13561357
13571358 @property
13581359 def state (self ) -> str :
0 commit comments