@@ -138,6 +138,14 @@ def _async_statement_reader(owner: Any) -> Any:
138138 return reader ()
139139
140140
141+ def _read_num_modified_rows (handle : Any ) -> Optional [int ]:
142+ try :
143+ modified = getattr (handle , "num_modified_rows" , None )
144+ return modified () if callable (modified ) else modified
145+ except Exception :
146+ return None
147+
148+
141149def _catalog_or_none (value : Optional [str ]) -> Optional [str ]:
142150 """Map supported all-catalog wildcards to the kernel's unset filter."""
143151 if value is None or value in ("%" , "*" ):
@@ -691,12 +699,7 @@ def execute_command(
691699 # default. ``getattr`` guards against an older kernel wheel that
692700 # predates the pyo3 getter. NB the Thrift backend also hardcodes
693701 # ``-1`` here, so this makes the kernel path *exceed* Thrift.
694- try :
695- modified = getattr (executed , "num_modified_rows" , None )
696- if callable (modified ):
697- modified = modified ()
698- except Exception :
699- modified = None
702+ modified = _read_num_modified_rows (executed )
700703 if modified is not None :
701704 cursor .rowcount = modified
702705 # ``KernelResultSet.__init__`` calls ``arrow_schema()`` which
@@ -969,7 +972,7 @@ def get_execution_result(
969972 result_set = self ._make_result_set (stream , cursor , command_id )
970973 # Older kernel wheels do not expose this value. Keep them compatible
971974 # while allowing a newer binding to populate async rowcount.
972- result_set .num_modified_rows = getattr (handle , "num_modified_rows" , None )
975+ result_set .num_modified_rows = _read_num_modified_rows (handle )
973976 return result_set
974977 except Exception as exc :
975978 raise _wrap_kernel_exception ("get_execution_result" , exc ) from exc
0 commit comments