@@ -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,21 @@ 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``, allows to ignore schema
741
+ changes on the server, schema updates are not automatically
742
+ loaded. 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
+ Calling the :meth:`~tarantool.Connection.update_schema`
751
+ method causes this parameter to switch
752
+ from ``False`` to ``True``.
753
+ :type fetch_schema: :obj:`bool`, optional
754
+
739
755
:raise: :exc:`~tarantool.error.ConfigurationError`,
740
756
:meth:`~tarantool.Connection.connect` exceptions
741
757
@@ -766,8 +782,9 @@ def __init__(self, host, port,
766
782
self .socket_timeout = socket_timeout
767
783
self .reconnect_delay = reconnect_delay
768
784
self .reconnect_max_attempts = reconnect_max_attempts
785
+ self .fetch_schema = fetch_schema
769
786
self .schema = Schema (self )
770
- self .schema_version = 1
787
+ self .schema_version = 0
771
788
self ._socket = None
772
789
self .connected = False
773
790
self .error = True
@@ -1023,7 +1040,8 @@ def connect(self):
1023
1040
if self .transport == SSL_TRANSPORT :
1024
1041
self .wrap_socket_ssl ()
1025
1042
self .handshake ()
1026
- self .load_schema ()
1043
+ if self .schema .schema != {}:
1044
+ self .load_schema ()
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 .schema != {}:
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 .fetch_schema == False :
1278
+ self .fetch_schema = True
1279
+
1258
1280
self .schema_version = schema_version
1259
1281
self .flush_schema ()
1260
1282
@@ -1269,6 +1291,18 @@ def flush_schema(self):
1269
1291
self .schema .flush ()
1270
1292
self .load_schema ()
1271
1293
1294
+ def _fetch_schema_support_check (self ):
1295
+ """
1296
+ Checks the fetch_schema opt of the connection is enabled.
1297
+ If the opt is disabled, an exception will be thrown
1298
+ about unsupporting the method with fetch_schema=False.
1299
+
1300
+ :raise: :exc:`~tarantool.error.NotSupportedError`
1301
+ """
1302
+ if not self .fetch_schema :
1303
+ raise NotSupportedError ('This method is not available in ' +
1304
+ 'connection opened with fetch_schema=False' )
1305
+
1272
1306
def call (self , func_name , * args , on_push = None , on_push_ctx = None ):
1273
1307
"""
1274
1308
Execute a CALL request: call a stored Lua function.
@@ -1366,11 +1400,14 @@ def replace(self, space_name, values, on_push=None, on_push_ctx=None):
1366
1400
:exc:`~tarantool.error.DatabaseError`,
1367
1401
:exc:`~tarantool.error.SchemaError`,
1368
1402
:exc:`~tarantool.error.NetworkError`,
1369
- :exc:`~tarantool.error.SslError`
1403
+ :exc:`~tarantool.error.SslError`,
1404
+ :exc:`~tarantool.error.NotSupportedError`
1370
1405
1371
1406
.. _replace: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/replace/
1372
1407
"""
1373
1408
1409
+ self ._fetch_schema_support_check ()
1410
+
1374
1411
if isinstance (space_name , str ):
1375
1412
space_name = self .schema .get_space (space_name ).sid
1376
1413
if on_push is not None and not callable (on_push ):
@@ -1411,7 +1448,7 @@ def authenticate(self, user, password):
1411
1448
password = self .password ,
1412
1449
auth_type = self ._get_auth_type ())
1413
1450
auth_response = self ._send_request_wo_reconnect (request )
1414
- if auth_response .return_code == 0 :
1451
+ if auth_response .return_code == 0 and self . schema . schema != {} :
1415
1452
self .flush_schema ()
1416
1453
return auth_response
1417
1454
@@ -1584,11 +1621,14 @@ def insert(self, space_name, values, on_push=None, on_push_ctx=None):
1584
1621
:exc:`~tarantool.error.DatabaseError`,
1585
1622
:exc:`~tarantool.error.SchemaError`,
1586
1623
:exc:`~tarantool.error.NetworkError`,
1587
- :exc:`~tarantool.error.SslError`
1624
+ :exc:`~tarantool.error.SslError`,
1625
+ :exc:`~tarantool.error.NotSupportedError`
1588
1626
1589
1627
.. _insert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/insert/
1590
1628
"""
1591
1629
1630
+ self ._fetch_schema_support_check ()
1631
+
1592
1632
if isinstance (space_name , str ):
1593
1633
space_name = self .schema .get_space (space_name ).sid
1594
1634
if on_push is not None and not callable (on_push ):
@@ -1623,11 +1663,14 @@ def delete(self, space_name, key, *, index=0, on_push=None, on_push_ctx=None):
1623
1663
:exc:`~tarantool.error.DatabaseError`,
1624
1664
:exc:`~tarantool.error.SchemaError`,
1625
1665
:exc:`~tarantool.error.NetworkError`,
1626
- :exc:`~tarantool.error.SslError`
1666
+ :exc:`~tarantool.error.SslError`,
1667
+ :exc:`~tarantool.error.NotSupportedError`
1627
1668
1628
1669
.. _delete: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/delete/
1629
1670
"""
1630
1671
1672
+ self ._fetch_schema_support_check ()
1673
+
1631
1674
key = wrap_key (key )
1632
1675
if isinstance (space_name , str ):
1633
1676
space_name = self .schema .get_space (space_name ).sid
@@ -1682,11 +1725,14 @@ def upsert(self, space_name, tuple_value, op_list, *, index=0, on_push=None, on_
1682
1725
:exc:`~tarantool.error.DatabaseError`,
1683
1726
:exc:`~tarantool.error.SchemaError`,
1684
1727
:exc:`~tarantool.error.NetworkError`,
1685
- :exc:`~tarantool.error.SslError`
1728
+ :exc:`~tarantool.error.SslError`,
1729
+ :exc:`~tarantool.error.NotSupportedError`
1686
1730
1687
1731
.. _upsert: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/upsert/
1688
1732
"""
1689
1733
1734
+ self ._fetch_schema_support_check ()
1735
+
1690
1736
if isinstance (space_name , str ):
1691
1737
space_name = self .schema .get_space (space_name ).sid
1692
1738
if isinstance (index , str ):
@@ -1770,11 +1816,14 @@ def update(self, space_name, key, op_list, *, index=0, on_push=None, on_push_ctx
1770
1816
:exc:`~tarantool.error.DatabaseError`,
1771
1817
:exc:`~tarantool.error.SchemaError`,
1772
1818
:exc:`~tarantool.error.NetworkError`,
1773
- :exc:`~tarantool.error.SslError`
1819
+ :exc:`~tarantool.error.SslError`,
1820
+ :exc:`~tarantool.error.NotSupportedError`
1774
1821
1775
1822
.. _update: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/update/
1776
1823
"""
1777
1824
1825
+ self ._fetch_schema_support_check ()
1826
+
1778
1827
key = wrap_key (key )
1779
1828
if isinstance (space_name , str ):
1780
1829
space_name = self .schema .get_space (space_name ).sid
@@ -1956,11 +2005,14 @@ def select(self, space_name, key=None, *, offset=0, limit=0xffffffff, index=0, i
1956
2005
:exc:`~tarantool.error.DatabaseError`,
1957
2006
:exc:`~tarantool.error.SchemaError`,
1958
2007
:exc:`~tarantool.error.NetworkError`,
1959
- :exc:`~tarantool.error.SslError`
2008
+ :exc:`~tarantool.error.SslError`,
2009
+ :exc:`~tarantool.error.NotSupportedError`
1960
2010
1961
2011
.. _select: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/select/
1962
2012
"""
1963
2013
2014
+ self ._fetch_schema_support_check ()
2015
+
1964
2016
if iterator is None :
1965
2017
iterator = ITERATOR_EQ
1966
2018
if key is None or (isinstance (key , (list , tuple )) and
@@ -1996,6 +2048,8 @@ def space(self, space_name):
1996
2048
:raise: :exc:`~tarantool.error.SchemaError`
1997
2049
"""
1998
2050
2051
+ self ._fetch_schema_support_check ()
2052
+
1999
2053
return Space (self , space_name )
2000
2054
2001
2055
def generate_sync (self ):
0 commit comments