1717import six
1818import threading
1919
20- from cassandra .cluster import Cluster , _NOT_SET , NoHostAvailable , UserTypeDoesNotExist , ConsistencyLevel
20+ from cassandra .cluster import Cluster , _NOT_SET , NoHostAvailable , UserTypeDoesNotExist
2121from cassandra .query import SimpleStatement , dict_factory
2222
2323from cassandra .cqlengine import CQLEngineException
@@ -62,7 +62,6 @@ class Connection(object):
6262 name = None
6363 hosts = None
6464
65- consistency = None
6665 retry_connect = False
6766 lazy_connect = False
6867 lazy_connect_lock = None
@@ -71,11 +70,9 @@ class Connection(object):
7170 cluster = None
7271 session = None
7372
74- def __init__ (self , name , hosts , consistency = None ,
75- lazy_connect = False , retry_connect = False , cluster_options = None ):
73+ def __init__ (self , name , hosts , lazy_connect = False , retry_connect = False , cluster_options = None ):
7674 self .hosts = hosts
7775 self .name = name
78- self .consistency = consistency
7976 self .lazy_connect = lazy_connect
8077 self .retry_connect = retry_connect
8178 self .cluster_options = cluster_options if cluster_options else {}
@@ -108,17 +105,14 @@ def setup(self):
108105 self .lazy_connect = True
109106 raise
110107
111- if self .consistency is not None :
112- self .session .default_consistency_level = self .consistency
113-
114108 if DEFAULT_CONNECTION in _connections and _connections [DEFAULT_CONNECTION ] == self :
115109 cluster = _connections [DEFAULT_CONNECTION ].cluster
116110 session = _connections [DEFAULT_CONNECTION ].session
117111
118112 self .setup_session ()
119113
120114 def setup_session (self ):
121- self .session .row_factory = dict_factory
115+ self .session .cluster . profile_manager . default . row_factory = dict_factory
122116 enc = self .session .encoder
123117 enc .mapping [tuple ] = enc .cql_encode_tuple
124118 _register_known_types (self .session .cluster )
@@ -139,21 +133,16 @@ def handle_lazy_connect(self):
139133 self .setup ()
140134
141135
142- def register_connection (name , hosts = None , consistency = None , lazy_connect = False ,
143- retry_connect = False , cluster_options = None , default = False ,
144- session = None ):
136+ def register_connection (name , hosts = None , lazy_connect = False , retry_connect = False ,
137+ cluster_options = None , default = False , session = None ):
145138 """
146139 Add a connection to the connection registry. ``hosts`` and ``session`` are
147- mutually exclusive, and ``consistency ``, ``lazy_connect ``,
148- ``retry_connect``, and ``cluster_options`` only work with ``hosts``. Using
140+ mutually exclusive, and ``lazy_connect ``, ``retry_connect ``,
141+ and ``cluster_options`` only work with ``hosts``. Using
149142 ``hosts`` will create a new :class:`cassandra.cluster.Cluster` and
150143 :class:`cassandra.cluster.Session`.
151144
152145 :param list hosts: list of hosts, (``contact_points`` for :class:`cassandra.cluster.Cluster`).
153- :param int consistency: The default :class:`~.ConsistencyLevel` for the
154- registered connection's new session. Default is the same as
155- :attr:`.Session.default_consistency_level`. For use with ``hosts`` only;
156- will fail when used with ``session``.
157146 :param bool lazy_connect: True if should not connect until first use. For
158147 use with ``hosts`` only; will fail when used with ``session``.
159148 :param bool retry_connect: True if we should retry to connect even if there
@@ -173,7 +162,6 @@ def register_connection(name, hosts=None, consistency=None, lazy_connect=False,
173162
174163 if session is not None :
175164 invalid_config_args = (hosts is not None or
176- consistency is not None or
177165 lazy_connect is not False or
178166 retry_connect is not False or
179167 cluster_options is not None )
@@ -184,12 +172,10 @@ def register_connection(name, hosts=None, consistency=None, lazy_connect=False,
184172 conn = Connection .from_session (name , session = session )
185173 conn .setup_session ()
186174 else : # use hosts argument
187- if consistency is None :
188- consistency = ConsistencyLevel .LOCAL_ONE
189175 conn = Connection (
190176 name , hosts = hosts ,
191- consistency = consistency , lazy_connect = lazy_connect ,
192- retry_connect = retry_connect , cluster_options = cluster_options
177+ lazy_connect = lazy_connect , retry_connect = retry_connect ,
178+ cluster_options = cluster_options
193179 )
194180 conn .setup ()
195181
@@ -282,8 +268,8 @@ def set_session(s):
282268 if conn .session :
283269 log .warning ("configuring new default connection for cqlengine when one was already set" )
284270
285- if s .row_factory is not dict_factory :
286- raise CQLEngineException ("Failed to initialize: 'Session .row_factory' must be 'dict_factory'." )
271+ if s .cluster . profile_manager . default . row_factory is not dict_factory :
272+ raise CQLEngineException ("Failed to initialize: the default 'ExecutionProfile .row_factory' must be 'dict_factory'." )
287273 conn .session = s
288274 conn .cluster = s .cluster
289275
@@ -300,7 +286,6 @@ def set_session(s):
300286def setup (
301287 hosts ,
302288 default_keyspace ,
303- consistency = None ,
304289 lazy_connect = False ,
305290 retry_connect = False ,
306291 ** kwargs ):
@@ -309,7 +294,6 @@ def setup(
309294
310295 :param list hosts: list of hosts, (``contact_points`` for :class:`cassandra.cluster.Cluster`)
311296 :param str default_keyspace: The default keyspace to use
312- :param int consistency: The global default :class:`~.ConsistencyLevel` - default is the same as :attr:`.Session.default_consistency_level`
313297 :param bool lazy_connect: True if should not connect until first use
314298 :param bool retry_connect: True if we should retry to connect even if there was a connection failure initially
315299 :param \*\*kwargs: Pass-through keyword arguments for :class:`cassandra.cluster.Cluster`
@@ -318,7 +302,7 @@ def setup(
318302 from cassandra .cqlengine import models
319303 models .DEFAULT_KEYSPACE = default_keyspace
320304
321- register_connection ('default' , hosts = hosts , consistency = consistency , lazy_connect = lazy_connect ,
305+ register_connection ('default' , hosts = hosts , lazy_connect = lazy_connect ,
322306 retry_connect = retry_connect , cluster_options = kwargs , default = True )
323307
324308
0 commit comments