@@ -53,6 +53,7 @@ def __init__(
5353 time_zone = None ,
5454 jwt_token = None ,
5555 compress : Union [int , bool ] = 8192 ,
56+ probe : bool = True ,
5657 ):
5758 """
5859 :param servers:
@@ -139,6 +140,13 @@ def __init__(
139140 ``False`` disables compression entirely.
140141 ``True`` compresses every request regardless of size.
141142 An integer compresses only when the payload exceeds that many bytes.
143+ :param probe:
144+ (optional, defaults to ``True``)
145+ Contact the servers while the connection is created, and raise
146+ ``ConnectionError`` when none of them responds.
147+ With ``False``, creating the connection performs no request, and
148+ the server version is resolved when it is first read. An
149+ unreachable cluster then fails on the first statement.
142150 """ # noqa: E501
143151
144152 self ._converter = converter
@@ -168,9 +176,30 @@ def __init__(
168176 jwt_token = jwt_token ,
169177 compress = compress ,
170178 )
171- self .lowest_server_version = self ._lowest_server_version ()
179+ self ._version_cache : Union [Version , None ] = None
180+ if probe :
181+ self ._version_cache = self ._lowest_server_version ()
172182 self ._closed = False
173183
184+ @property
185+ def lowest_server_version (self ) -> Version :
186+ """
187+ The lowest CrateDB version among the servers of this connection.
188+
189+ Without a version from the servers, comparisons against it still work,
190+ and report the servers as older than any released CrateDB.
191+ """
192+ if self ._version_cache is not None :
193+ return self ._version_cache
194+ version = self ._lowest_server_version (strict = False )
195+ if version > Version ("0.0.0" ):
196+ self ._version_cache = version
197+ return version
198+
199+ @lowest_server_version .setter
200+ def lowest_server_version (self , version : Version ) -> None :
201+ self ._version_cache = version
202+
174203 def cursor (self , ** kwargs ) -> Cursor :
175204 """
176205 Return a new Cursor Object using the connection.
@@ -208,7 +237,7 @@ def get_blob_container(self, container_name):
208237 """
209238 return BlobContainer (container_name , self )
210239
211- def _lowest_server_version (self ) :
240+ def _lowest_server_version (self , strict : bool = True ) -> Version :
212241 lowest = None
213242 servers = self .client .active_servers
214243 connection_errors = []
@@ -223,7 +252,7 @@ def _lowest_server_version(self):
223252 continue
224253 if not lowest or version < lowest :
225254 lowest = version
226- if connection_errors and not lowest :
255+ if strict and connection_errors and not lowest :
227256 raise ConnectionError ("; " .join (str (e ) for e in connection_errors ))
228257 return lowest or Version ("0.0.0" )
229258
0 commit comments