MCPcopy Index your code
hub / github.com/apache/cassandra-python-driver / _execute_after_prepare

Method _execute_after_prepare

cassandra/cluster.py:4839–4891  ·  view source on GitHub ↗

Handle the response to our attempt to prepare a statement. If it succeeded, run the original query again against the same host.

(self, host, connection, pool, response)

Source from the content-addressed store, hash-verified

4837 "Failed to set keyspace on all hosts: %s" % (errors,)))
4838
4839 def _execute_after_prepare(self, host, connection, pool, response):
4840 """
4841 Handle the response to our attempt to prepare a statement.
4842 If it succeeded, run the original query again against the same host.
4843 """
4844 if pool:
4845 pool.return_connection(connection)
4846
4847 if self._final_exception:
4848 return
4849
4850 if isinstance(response, ResultMessage):
4851 if response.kind == RESULT_KIND_PREPARED:
4852 if self.prepared_statement:
4853 if self.prepared_statement.query_id != response.query_id:
4854 self._set_final_exception(DriverException(
4855 "ID mismatch while trying to reprepare (expected {expected}, got {got}). "
4856 "This prepared statement won't work anymore. "
4857 "This usually happens when you run a 'USE...' "
4858 "query after the statement was prepared.".format(
4859 expected=hexlify(self.prepared_statement.query_id), got=hexlify(response.query_id)
4860 )
4861 ))
4862 self.prepared_statement.result_metadata = response.column_metadata
4863 new_metadata_id = response.result_metadata_id
4864 if new_metadata_id is not None:
4865 self.prepared_statement.result_metadata_id = new_metadata_id
4866
4867 # use self._query to re-use the same host and
4868 # at the same time properly borrow the connection
4869 request_id = self._query(host)
4870 if request_id is None:
4871 # this host errored out, move on to the next
4872 self.send_request()
4873 else:
4874 self._set_final_exception(ConnectionException(
4875 "Got unexpected response when preparing statement "
4876 "on host %s: %s" % (host, response)))
4877 elif isinstance(response, ErrorMessage):
4878 if hasattr(response, 'to_exception'):
4879 self._set_final_exception(response.to_exception())
4880 else:
4881 self._set_final_exception(response)
4882 elif isinstance(response, ConnectionException):
4883 log.debug("Connection error when preparing statement on host %s: %s",
4884 host, response)
4885 # try again on a different host, preparing again if necessary
4886 self._errors[host] = response
4887 self.send_request()
4888 else:
4889 self._set_final_exception(ConnectionException(
4890 "Got unexpected response type when preparing "
4891 "statement on host %s: %s" % (host, response)))
4892
4893 def _set_final_result(self, response):
4894 self._cancel_timer()

Calls 7

_set_final_exceptionMethod · 0.95
_queryMethod · 0.95
send_requestMethod · 0.95
DriverExceptionClass · 0.90
ConnectionExceptionClass · 0.90
return_connectionMethod · 0.45
to_exceptionMethod · 0.45