@@ -579,7 +579,8 @@ def __init__(self, host, port,
579
579
ssl_password_file = DEFAULT_SSL_PASSWORD_FILE ,
580
580
packer_factory = default_packer_factory ,
581
581
unpacker_factory = default_unpacker_factory ,
582
- auth_type = None ):
582
+ auth_type = None ,
583
+ fetch_schema = True ):
583
584
"""
584
585
:param host: Server hostname or IP address. Use ``None`` for
585
586
Unix sockets.
@@ -736,6 +737,18 @@ def __init__(self, host, port,
736
737
``"chap-sha1"``.
737
738
:type auth_type: :obj:`None` or :obj:`str`, optional
738
739
740
+ :param bool fetch_schema: If ``False``, schema is not loaded on connect
741
+ and schema updates are not automatically loaded.
742
+ As a result, these methods become unavailable:
743
+ :meth:`~tarantool.Connection.replace`,
744
+ :meth:`~tarantool.Connection.insert`,
745
+ :meth:`~tarantool.Connection.delete`,
746
+ :meth:`~tarantool.Connection.upsert`,
747
+ :meth:`~tarantool.Connection.update`,
748
+ :meth:`~tarantool.Connection.select`,
749
+ :meth:`~tarantool.Connection.space`.
750
+ :type fetch_schema: :obj:`bool`, optional
751
+
739
752
:raise: :exc:`~tarantool.error.ConfigurationError`,
740
753
:meth:`~tarantool.Connection.connect` exceptions
741
754
@@ -766,8 +779,9 @@ def __init__(self, host, port,
766
779
self .socket_timeout = socket_timeout
767
780
self .reconnect_delay = reconnect_delay
768
781
self .reconnect_max_attempts = reconnect_max_attempts
769
- self .schema = Schema (self )
770
- self .schema_version = 1
782
+ self .fetch_schema = fetch_schema
783
+ self .schema = None
784
+ self .schema_version = 0
771
785
self ._socket = None
772
786
self .connected = False
773
787
self .error = True
@@ -1023,7 +1037,11 @@ def connect(self):
1023
1037
if self .transport == SSL_TRANSPORT :
1024
1038
self .wrap_socket_ssl ()
1025
1039
self .handshake ()
1026
- self .load_schema ()
1040
+ if self .fetch_schema :
1041
+ self .schema = Schema (self )
1042
+ self .load_schema ()
1043
+ else :
1044
+ self .schema = None
1027
1045
except SslError as e :
1028
1046
raise e
1029
1047
except Exception as e :
@@ -1118,7 +1136,8 @@ def _send_request_wo_reconnect(self, request, on_push=None, on_push_ctx=None):
1118
1136
response = request .response_class (self , self ._read_response ())
1119
1137
break
1120
1138
except SchemaReloadException as e :
1121
- self .update_schema (e .schema_version )
1139
+ if self .schema is not None :
1140
+ self .update_schema (e .schema_version )
1122
1141
continue
1123
1142
1124
1143
while response ._code == IPROTO_CHUNK :
@@ -1255,6 +1274,9 @@ def update_schema(self, schema_version):
1255
1274
:meta private:
1256
1275
"""
1257
1276
1277
+ if self .schema is None :
1278
+ self .schema = Schema (self )
1279
+
1258
1280
self .schema_version = schema_version
1259
1281
self .flush_schema ()
1260
1282
@@ -1269,6 +1291,19 @@ def flush_schema(self):
1269
1291
self .schema .flush ()
1270
1292
self .load_schema ()
1271
1293
1294
+ def _schemaful_connection_check (self ):
1295
+ """
1296
+ Checks whether the connection is schemaful.
1297
+ If the connection is schemaless, an exception will be thrown
1298
+ about unsupporting the method in connection opened
1299
+ with fetch_schema=False.
1300
+
1301
+ :raise: :exc:`~tarantool.error.NotSupportedError`
1302
+ """
1303
+ if self .schema is None :
1304
+ raise NotSupportedError ('This method is not available in ' +
1305
+ 'connection opened with fetch_schema=False' )
1306
+
1272
1307
def call (self , func_name , * args , on_push = None , on_push_ctx = None ):
1273
1308
"""
1274
1309
Execute a CALL request: call a stored Lua function.
@@ -1366,11 +1401,14 @@ def replace(self, space_name, values, on_push=None, on_push_ctx=None):
1366
1401
:exc:`~tarantool.error.DatabaseError`,
1367
1402
:exc:`~tarantool.error.SchemaError`,
1368
1403
:exc:`~tarantool.error.NetworkError`,
1369
- :exc:`~tarantool.error.SslError`
1404
+ :exc:`~tarantool.error.SslError`,
1405
+ :exc:`~tarantool.error.NotSupportedError`
1370
1406
1371
1407
.. _replace: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/replace/
1372
1408
"""
1373
1409
1410
+ self ._schemaful_connection_check ()
1411
+
1374
1412
if isinstance (space_name , str ):
1375
1413
space_name = self .schema .get_space (space_name ).sid
1376
1414
if on_push is not None and not callable (on_push ):
@@ -1411,7 +1449,7 @@ def authenticate(self, user, password):
1411
1449
password = self .password ,
1412
1450
auth_type = self ._get_auth_type ())
1413
1451
auth_response = self ._send_request_wo_reconnect (request )
1414
- if auth_response .return_code == 0 :
1452
+ if auth_response .return_code == 0 and self . schema is not None :
1415
1453
self .flush_schema ()
1416
1454
return auth_response
1417
1455
@@ -1584,11 +1622,14 @@ def insert(self, space_name, values, on_push=None, on_push_ctx=None):
1584
1622
:exc:`~tarantool.error.DatabaseError`,
1585
1623
:exc:`~tarantool.error.SchemaError`,
1586
1624
:exc:`~tarantool.error.NetworkError`,
1587
- :exc:`~tarantool.error.SslError`
1625
+ :exc:`~tarantool.error.SslError`,
1626
+ :exc:`~tarantool.error.NotSupportedError`
1588
1627
1589
1628
.. _insert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/insert/
1590
1629
"""
1591
1630
1631
+ self ._schemaful_connection_check ()
1632
+
1592
1633
if isinstance (space_name , str ):
1593
1634
space_name = self .schema .get_space (space_name ).sid
1594
1635
if on_push is not None and not callable (on_push ):
@@ -1623,11 +1664,14 @@ def delete(self, space_name, key, *, index=0, on_push=None, on_push_ctx=None):
1623
1664
:exc:`~tarantool.error.DatabaseError`,
1624
1665
:exc:`~tarantool.error.SchemaError`,
1625
1666
:exc:`~tarantool.error.NetworkError`,
1626
- :exc:`~tarantool.error.SslError`
1667
+ :exc:`~tarantool.error.SslError`,
1668
+ :exc:`~tarantool.error.NotSupportedError`
1627
1669
1628
1670
.. _delete: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/delete/
1629
1671
"""
1630
1672
1673
+ self ._schemaful_connection_check ()
1674
+
1631
1675
key = wrap_key (key )
1632
1676
if isinstance (space_name , str ):
1633
1677
space_name = self .schema .get_space (space_name ).sid
@@ -1682,11 +1726,14 @@ def upsert(self, space_name, tuple_value, op_list, *, index=0, on_push=None, on_
1682
1726
:exc:`~tarantool.error.DatabaseError`,
1683
1727
:exc:`~tarantool.error.SchemaError`,
1684
1728
:exc:`~tarantool.error.NetworkError`,
1685
- :exc:`~tarantool.error.SslError`
1729
+ :exc:`~tarantool.error.SslError`,
1730
+ :exc:`~tarantool.error.NotSupportedError`
1686
1731
1687
1732
.. _upsert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/upsert/
1688
1733
"""
1689
1734
1735
+ self ._schemaful_connection_check ()
1736
+
1690
1737
if isinstance (space_name , str ):
1691
1738
space_name = self .schema .get_space (space_name ).sid
1692
1739
if isinstance (index , str ):
@@ -1770,11 +1817,14 @@ def update(self, space_name, key, op_list, *, index=0, on_push=None, on_push_ctx
1770
1817
:exc:`~tarantool.error.DatabaseError`,
1771
1818
:exc:`~tarantool.error.SchemaError`,
1772
1819
:exc:`~tarantool.error.NetworkError`,
1773
- :exc:`~tarantool.error.SslError`
1820
+ :exc:`~tarantool.error.SslError`,
1821
+ :exc:`~tarantool.error.NotSupportedError`
1774
1822
1775
1823
.. _update: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/update/
1776
1824
"""
1777
1825
1826
+ self ._schemaful_connection_check ()
1827
+
1778
1828
key = wrap_key (key )
1779
1829
if isinstance (space_name , str ):
1780
1830
space_name = self .schema .get_space (space_name ).sid
@@ -1956,11 +2006,14 @@ def select(self, space_name, key=None, *, offset=0, limit=0xffffffff, index=0, i
1956
2006
:exc:`~tarantool.error.DatabaseError`,
1957
2007
:exc:`~tarantool.error.SchemaError`,
1958
2008
:exc:`~tarantool.error.NetworkError`,
1959
- :exc:`~tarantool.error.SslError`
2009
+ :exc:`~tarantool.error.SslError`,
2010
+ :exc:`~tarantool.error.NotSupportedError`
1960
2011
1961
2012
.. _select: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/select/
1962
2013
"""
1963
2014
2015
+ self ._schemaful_connection_check ()
2016
+
1964
2017
if iterator is None :
1965
2018
iterator = ITERATOR_EQ
1966
2019
if key is None or (isinstance (key , (list , tuple )) and
@@ -1996,6 +2049,8 @@ def space(self, space_name):
1996
2049
:raise: :exc:`~tarantool.error.SchemaError`
1997
2050
"""
1998
2051
2052
+ self ._schemaful_connection_check ()
2053
+
1999
2054
return Space (self , space_name )
2000
2055
2001
2056
def generate_sync (self ):
0 commit comments