snowflake-connector-python 5.2.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. snowflake/connector/__init__.py +148 -0
  2. snowflake/connector/_common/__init__.py +0 -0
  3. snowflake/connector/_common/extras.py +134 -0
  4. snowflake/connector/_common/telemetry.py +221 -0
  5. snowflake/connector/_common/wif_util.py +92 -0
  6. snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
  7. snowflake/connector/_core/sf_core_python.pyi +79 -0
  8. snowflake/connector/_internal/__init__.py +6 -0
  9. snowflake/connector/_internal/_private_key_helper.py +31 -0
  10. snowflake/connector/_internal/api_client/__init__.py +93 -0
  11. snowflake/connector/_internal/api_client/bridge.py +41 -0
  12. snowflake/connector/_internal/api_client/client_api.py +976 -0
  13. snowflake/connector/_internal/arrow.py +47 -0
  14. snowflake/connector/_internal/arrow_context.py +240 -0
  15. snowflake/connector/_internal/arrow_stream_async.py +266 -0
  16. snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
  17. snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
  18. snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
  19. snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
  20. snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
  21. snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
  22. snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
  23. snowflake/connector/_internal/arrow_stream_utils.py +171 -0
  24. snowflake/connector/_internal/authenticator_type.py +53 -0
  25. snowflake/connector/_internal/backward_compatibility.py +245 -0
  26. snowflake/connector/_internal/binding_converters.py +741 -0
  27. snowflake/connector/_internal/config_utils.py +71 -0
  28. snowflake/connector/_internal/connection/__init__.py +39 -0
  29. snowflake/connector/_internal/connection/connection.py +616 -0
  30. snowflake/connector/_internal/connection/connection_types.py +13 -0
  31. snowflake/connector/_internal/connection/constants.py +25 -0
  32. snowflake/connector/_internal/connection/decorators.py +31 -0
  33. snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
  34. snowflake/connector/_internal/connection/queries.py +10 -0
  35. snowflake/connector/_internal/connection_config_mixin.py +755 -0
  36. snowflake/connector/_internal/cursor/__init__.py +25 -0
  37. snowflake/connector/_internal/cursor/base.py +732 -0
  38. snowflake/connector/_internal/cursor/cursor_types.py +13 -0
  39. snowflake/connector/_internal/cursor/decorators.py +56 -0
  40. snowflake/connector/_internal/cursor/query_result.py +202 -0
  41. snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
  42. snowflake/connector/_internal/cursor/result_metadata.py +255 -0
  43. snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
  44. snowflake/connector/_internal/decorators.py +539 -0
  45. snowflake/connector/_internal/error_kinds.py +111 -0
  46. snowflake/connector/_internal/errorcode.py +35 -0
  47. snowflake/connector/_internal/errorhandler.py +278 -0
  48. snowflake/connector/_internal/fips.py +28 -0
  49. snowflake/connector/_internal/logging/__init__.py +52 -0
  50. snowflake/connector/_internal/logging/config.py +134 -0
  51. snowflake/connector/_internal/logging/core_logger.py +218 -0
  52. snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
  53. snowflake/connector/_internal/logout_config_mapping.py +187 -0
  54. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
  55. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  56. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
  57. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
  58. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
  59. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  60. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  61. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  62. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
  63. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
  64. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
  65. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
  66. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
  67. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
  68. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
  69. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
  70. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
  71. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  72. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
  73. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  74. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
  75. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
  76. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
  77. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  78. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
  79. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  80. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  81. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  82. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
  83. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
  84. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
  85. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  86. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
  87. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  88. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
  89. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  90. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  91. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
  92. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
  93. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
  94. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
  95. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  96. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
  97. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  98. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
  99. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  100. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
  101. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
  102. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  103. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  104. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  105. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
  106. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
  107. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
  108. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
  109. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  110. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
  111. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
  112. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
  113. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  114. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
  115. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
  116. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  117. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  118. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  119. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
  120. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
  121. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
  122. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  123. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
  124. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
  125. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
  126. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  127. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  128. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
  129. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
  130. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  131. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  132. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  133. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  134. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  135. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
  136. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
  137. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
  138. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  139. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  140. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
  141. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
  142. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
  143. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
  144. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
  145. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
  146. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
  147. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
  148. snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
  149. snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
  150. snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
  151. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
  152. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
  153. snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
  154. snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
  155. snowflake/connector/_internal/result_batch.py +150 -0
  156. snowflake/connector/_internal/snowflake_restful.py +222 -0
  157. snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
  158. snowflake/connector/_internal/sqlstate.py +11 -0
  159. snowflake/connector/_internal/statement_utils.py +207 -0
  160. snowflake/connector/_internal/text_utils.py +112 -0
  161. snowflake/connector/_internal/type_codes.py +139 -0
  162. snowflake/connector/_internal/utils.py +65 -0
  163. snowflake/connector/_internal/write_pandas_operation.py +657 -0
  164. snowflake/connector/aio/README.md +168 -0
  165. snowflake/connector/aio/__init__.py +37 -0
  166. snowflake/connector/aio/connection/__init__.py +17 -0
  167. snowflake/connector/aio/connection/_connection.py +506 -0
  168. snowflake/connector/aio/cursor/__init__.py +35 -0
  169. snowflake/connector/aio/cursor/_base.py +1034 -0
  170. snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
  171. snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
  172. snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
  173. snowflake/connector/aio/pandas_tools.py +279 -0
  174. snowflake/connector/aio/result_batch.py +165 -0
  175. snowflake/connector/auth/__init__.py +0 -0
  176. snowflake/connector/auth/workload_identity.py +5 -0
  177. snowflake/connector/compat.py +22 -0
  178. snowflake/connector/config_manager.py +392 -0
  179. snowflake/connector/connection/__init__.py +30 -0
  180. snowflake/connector/connection/_connection.py +641 -0
  181. snowflake/connector/connection_config.py +517 -0
  182. snowflake/connector/constants.py +52 -0
  183. snowflake/connector/cursor/__init__.py +37 -0
  184. snowflake/connector/cursor/_base.py +1169 -0
  185. snowflake/connector/cursor/_chunked_download_reader.py +75 -0
  186. snowflake/connector/cursor/_dict_cursor.py +78 -0
  187. snowflake/connector/cursor/_result_set_wrapper.py +35 -0
  188. snowflake/connector/cursor/_snowflake_cursor.py +72 -0
  189. snowflake/connector/description.py +7 -0
  190. snowflake/connector/errors.py +492 -0
  191. snowflake/connector/network.py +71 -0
  192. snowflake/connector/pandas_tools.py +191 -0
  193. snowflake/connector/py.typed +0 -0
  194. snowflake/connector/result_batch.py +216 -0
  195. snowflake/connector/telemetry.py +40 -0
  196. snowflake/connector/time_util.py +11 -0
  197. snowflake/connector/types.py +134 -0
  198. snowflake/connector/util_text.py +3 -0
  199. snowflake/connector/version.py +23 -0
  200. snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
  201. snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
  202. snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
  203. snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
  204. snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,492 @@
1
+ """
2
+ PEP 249 Database API 2.0 Exception Classes
3
+
4
+ This module defines the exception hierarchy for the Snowflake connector.
5
+
6
+ The **active** exceptions (raised at runtime) are the PEP 249 hierarchy plus a
7
+ handful of driver-specific types (``MissingDependencyError``, config errors,
8
+ ``ReauthenticationRequest``). These are what ``sf_core`` error kinds map to via
9
+ ``KIND_TO_EXCEPTION``.
10
+
11
+ Everything after the "Backward compatibility" section below exists solely so
12
+ that ``from snowflake.connector.errors import BadGatewayError`` (etc.) does not
13
+ break user code written against the old ``snowflake-connector-python`` driver.
14
+ None of these classes are raised by the universal core at runtime:
15
+
16
+ - **HTTP exceptions** (``BadRequest``, ``ServiceUnavailableError``, ...):
17
+ In the old driver, Python's ``requests`` library returned HTTP status codes
18
+ that were wrapped into typed exceptions and used as internal retry-loop
19
+ control flow signals. They leaked to users only when retries were
20
+ exhausted. In the universal core, the Rust core handles HTTP retries
21
+ internally; by the time an error reaches Python it is already mapped to a
22
+ PEP 249 type via ``ErrorKind``.
23
+
24
+ - **Auth / token exceptions** (``RefreshTokenError``, ``TokenExpiredError``):
25
+ Used in the old driver as internal signals between the OKTA authenticator
26
+ and the retry loop. The universal core handles token refresh in Rust.
27
+
28
+ - **TLS exception** (``RevocationCheckError``):
29
+ OCSP/CRL verification runs inside the Rust TLS layer.
30
+
31
+ - **File-transfer exceptions** (``BindUploadError``, ``RequestExceedMaxRetryError``,
32
+ ``PresignedUrlExpiredError``):
33
+ Stage upload/download retry logic is internal to the Rust core.
34
+
35
+ All backward-compatibility classes are marked with ``@backward_compatibility``.
36
+ """
37
+
38
+ from __future__ import annotations
39
+
40
+ import warnings
41
+
42
+ from typing import TYPE_CHECKING, Any, Protocol, TypedDict
43
+
44
+ from ._internal.backward_compatibility import install_backward_compatibility_getattr
45
+ from ._internal.decorators import backward_compatibility
46
+
47
+
48
+ if TYPE_CHECKING:
49
+ from .aio.connection import Connection as AsyncConnection
50
+ from .aio.cursor import SnowflakeCursorBase as AsyncSnowflakeCursorBase
51
+ from .connection import Connection
52
+ from .cursor import SnowflakeCursorBase
53
+
54
+
55
+ class ErrorDetails(TypedDict, total=False):
56
+ msg: str
57
+ errno: int
58
+ sqlstate: str | None
59
+ sfqid: str | None
60
+ query: str | None
61
+ request_id: str | None
62
+ parameter: str | None
63
+ validation_code: int | None
64
+
65
+
66
+ class StructuredErrorHandler(Protocol):
67
+ def __call__(
68
+ self,
69
+ connection: Connection | AsyncConnection | None,
70
+ cursor: SnowflakeCursorBase | AsyncSnowflakeCursorBase | None,
71
+ error_class: type[Error],
72
+ error_value: ErrorDetails,
73
+ ) -> None: ...
74
+
75
+
76
+ ErrorValue = ErrorDetails
77
+
78
+ # ---------------------------------------------------------------------------
79
+ # PEP 249 exception hierarchy (active — raised at runtime)
80
+ # ---------------------------------------------------------------------------
81
+
82
+
83
+ class Warning(Warning): # type: ignore[misc]
84
+ """Exception raised for important warnings like data truncations while inserting, etc."""
85
+
86
+ pass
87
+
88
+
89
+ class Error(Exception):
90
+ """Exception that is the base class of all other error exceptions.
91
+
92
+ In addition to being a standard PEP 249 exception base, this class provides
93
+ the **error-handler protocol** used throughout the driver to raise errors in
94
+ a way that is consistent with PEP 249 and backward-compatible with the old
95
+ ``snowflake-connector-python`` driver.
96
+ """
97
+
98
+ def __init__(
99
+ self,
100
+ msg: str = "",
101
+ errno: int = -1,
102
+ sqlstate: str | None = None,
103
+ sfqid: str | None = None,
104
+ query: str | None = None,
105
+ request_id: str | None = None,
106
+ parameter: str | None = None,
107
+ validation_code: int | None = None,
108
+ **kwargs: Any, # absorbs extra keys for backward compatibility with old driver code
109
+ ) -> None:
110
+ self.errno = errno
111
+ self.sqlstate = sqlstate
112
+ self.sfqid = sfqid
113
+ self.query = query
114
+ # Client-generated ``requestId`` sent on the query submission request.
115
+ # Populated for errors that originate from a query execution attempt;
116
+ # ``None`` for non-query errors (auth, config, transport).
117
+ self.request_id = request_id
118
+ self.raw_msg = msg
119
+ self.msg = self._format_message(msg)
120
+ # The offending config parameter and structured sf_core ValidationCode
121
+ # (see protobuf_gen's ValidationCode enum), when the error originated
122
+ # from a connection-config validation failure. None otherwise.
123
+ self.parameter = parameter
124
+ self.validation_code = validation_code
125
+ super().__init__(self.msg)
126
+
127
+ def __repr__(self) -> str:
128
+ return self.__str__()
129
+
130
+ def __str__(self) -> str:
131
+ if not self.msg:
132
+ return self.msg
133
+ ids = []
134
+ if self.request_id:
135
+ ids.append(f"request_id={self.request_id}")
136
+ if self.sfqid:
137
+ ids.append(f"sfqid={self.sfqid}")
138
+ return f"{self.msg} ({', '.join(ids)})" if ids else self.msg
139
+
140
+ def _format_message(self, msg: str) -> str:
141
+ code_str = f"{self.errno:06d}" if isinstance(self.errno, int) and self.errno >= 0 else "------"
142
+ sqlstate_str = f" ({self.sqlstate})" if self.sqlstate else ""
143
+ return f"{code_str}{sqlstate_str}: {msg}" if msg else ""
144
+
145
+ # ------------------------------------------------------------------
146
+ # Error-handler protocol (PEP 249 / backward compatible)
147
+ # ------------------------------------------------------------------
148
+
149
+ @staticmethod
150
+ def errorhandler_wrapper(
151
+ connection: Connection | AsyncConnection | None,
152
+ cursor: SnowflakeCursorBase | AsyncSnowflakeCursorBase | None,
153
+ error_class: type[Error],
154
+ error_value: ErrorDetails,
155
+ ) -> None:
156
+ """Raise an error through the error-handler chain.
157
+
158
+ This is the **single entry point** that all driver code should use to
159
+ report errors originating from connection or cursor operations.
160
+
161
+ The method first tries to hand the error to a user-supplied handler via
162
+ :pyfunc:`hand_to_other_handler`. If no handler was available (both
163
+ *connection* and *cursor* are ``None``), it falls back to creating and
164
+ raising the exception directly.
165
+ """
166
+ handed_over = Error.hand_to_other_handler(connection, cursor, error_class, error_value)
167
+ if not handed_over:
168
+ raise Error.errorhandler_make_exception(error_class, error_value)
169
+
170
+ @staticmethod
171
+ def hand_to_other_handler(
172
+ connection: Connection | AsyncConnection | None,
173
+ cursor: SnowflakeCursorBase | AsyncSnowflakeCursorBase | None,
174
+ error_class: type[Error],
175
+ error_value: ErrorDetails,
176
+ ) -> bool:
177
+ """Try to delegate the error to a connection's or cursor's error handler.
178
+
179
+ Records the error in the ``messages`` list of both the connection and
180
+ the cursor (when present), then invokes the first available handler.
181
+
182
+ Returns:
183
+ ``True`` if a handler was invoked, ``False`` if both *connection*
184
+ and *cursor* were ``None``.
185
+ """
186
+ if connection is not None:
187
+ connection.messages.append((error_class, error_value))
188
+ if cursor is not None:
189
+ cursor.messages.append((error_class, error_value))
190
+ cursor.errorhandler(connection, cursor, error_class, error_value)
191
+ return True
192
+ elif connection is not None:
193
+ connection.errorhandler(connection, cursor, error_class, error_value)
194
+ return True
195
+ return False
196
+
197
+ @staticmethod
198
+ def errorhandler_make_exception(
199
+ error_class: type[Error],
200
+ error_value: ErrorDetails,
201
+ ) -> Error:
202
+ """Create an exception instance from *error_class* and *error_value*.
203
+
204
+ Used as a fallback when no connection/cursor handler is available.
205
+ """
206
+ return error_class(
207
+ msg=error_value.get("msg", ""),
208
+ errno=error_value.get("errno", -1),
209
+ sqlstate=error_value.get("sqlstate"),
210
+ sfqid=error_value.get("sfqid"),
211
+ query=error_value.get("query"),
212
+ request_id=error_value.get("request_id"),
213
+ parameter=error_value.get("parameter"),
214
+ validation_code=error_value.get("validation_code"),
215
+ )
216
+
217
+ @staticmethod
218
+ def default_errorhandler(
219
+ connection: Connection | AsyncConnection | None,
220
+ cursor: SnowflakeCursorBase | AsyncSnowflakeCursorBase | None,
221
+ error_class: type[Error],
222
+ error_value: ErrorDetails,
223
+ ) -> None:
224
+ """Default error handler that simply raises the error.
225
+
226
+ This is the handler installed on every new ``Connection`` and ``Cursor``
227
+ unless the user overrides ``errorhandler``.
228
+ """
229
+ # circular-import: errorhandler.py imports Error from this module at top
230
+ # level, so this helper is imported at call time to avoid the cycle.
231
+ from ._internal.errorhandler import _mark_errorhandler_routed
232
+
233
+ new_exc = Error.errorhandler_make_exception(error_class, error_value)
234
+ # The reconstructed exception must carry the routed flag so a
235
+ # @simplified_error_handling caller does not PEP route twice
236
+ _mark_errorhandler_routed(new_exc)
237
+ raise new_exc
238
+
239
+
240
+ class InterfaceError(Error):
241
+ """
242
+ Exception raised for errors that are related to the database interface
243
+ rather than the database itself.
244
+ """
245
+
246
+ pass
247
+
248
+
249
+ class DatabaseError(Error):
250
+ """Exception raised for errors that are related to the database."""
251
+
252
+ pass
253
+
254
+
255
+ class DataError(DatabaseError):
256
+ """
257
+ Exception raised for errors that are due to problems with the processed data
258
+ like division by zero, numeric value out of range, etc.
259
+ """
260
+
261
+ pass
262
+
263
+
264
+ class OperationalError(DatabaseError):
265
+ """
266
+ Exception raised for errors that are related to the database's operation
267
+ and not necessarily under the control of the programmer.
268
+ """
269
+
270
+ #: HTTP status code, set when this error represents a raw HTTP failure
271
+ #: surfaced by ``SnowflakeRestful.fetch(..., raise_raw_http_failure=True)``.
272
+ #: ``None`` for operational errors that are not HTTP failures.
273
+ http_status: int | None = None
274
+
275
+ @classmethod
276
+ def from_http_response(cls, status_code: int, response_body: bytes) -> OperationalError:
277
+ """Build an error representing a raw HTTP failure (status >= 400).
278
+
279
+ The HTTP status is attached as :attr:`http_status` so consumers can
280
+ branch on it without parsing the message string. (The old driver raised
281
+ a vendored ``requests`` ``HTTPError`` carrying ``.response.status_code``;
282
+ this is the universal-driver equivalent.)
283
+ """
284
+ # Truncate body to avoid flooding error messages with large payloads.
285
+ error = cls(msg=f"HTTP {status_code}: {response_body[:200]!r}")
286
+ error.http_status = status_code
287
+ return error
288
+
289
+
290
+ class IntegrityError(DatabaseError):
291
+ """
292
+ Exception raised when the relational integrity of the database is affected,
293
+ e.g. a foreign key check fails.
294
+ """
295
+
296
+ pass
297
+
298
+
299
+ class InternalError(DatabaseError):
300
+ """Exception raised when the database encounters an internal error."""
301
+
302
+ pass
303
+
304
+
305
+ class ProgrammingError(DatabaseError):
306
+ """
307
+ Exception raised for programming errors, e.g. table not found or already exists,
308
+ syntax error in the SQL statement, wrong number of parameters specified, etc.
309
+ """
310
+
311
+ pass
312
+
313
+
314
+ class NotSupportedError(DatabaseError):
315
+ """
316
+ Exception raised in case a method or database API was used which is not
317
+ supported by the database.
318
+ """
319
+
320
+ pass
321
+
322
+
323
+ # ---------------------------------------------------------------------------
324
+ # Driver-specific exceptions (active — raised at runtime)
325
+ # ---------------------------------------------------------------------------
326
+
327
+ _FUTURE_BASE_CHANGE_WARNED = False
328
+
329
+
330
+ def _warn_future_base_change() -> None:
331
+ """Advise callers that ``ReauthenticationRequest``'s base will change.
332
+
333
+ An advisory must never shadow the failure it is advising about: wrapped in
334
+ try/except so a caller's ``filterwarnings("error")`` can't turn this into
335
+ the exception the caller receives instead of ``ReauthenticationRequest``.
336
+ Deduped once per process so a retry loop doesn't flood stderr.
337
+ """
338
+ global _FUTURE_BASE_CHANGE_WARNED
339
+ if _FUTURE_BASE_CHANGE_WARNED:
340
+ return
341
+ _FUTURE_BASE_CHANGE_WARNED = True
342
+ try:
343
+ warnings.warn(
344
+ "`ReauthenticationRequest` currently subclasses `ProgrammingError` for "
345
+ "compatibility with `snowflake-connector-python`. In a future major "
346
+ "release its base will change to `OperationalError`. If you catch this "
347
+ "via `except ProgrammingError`, switch to `except ReauthenticationRequest` "
348
+ "(or `except DatabaseError`) to stay correct across that change.",
349
+ FutureWarning,
350
+ stacklevel=3,
351
+ )
352
+ except Exception:
353
+ pass
354
+
355
+
356
+ # `ProgrammingError` isn't the PEP 249-correct base for token expiry (that's
357
+ # `OperationalError`), but it's what legacy raised, and `except ProgrammingError`
358
+ # is how existing callers catch this. Base changes to `OperationalError` in a
359
+ # future major release: TODO(SNOW-3965765).
360
+ class ReauthenticationRequest(ProgrammingError):
361
+ """Raised when the session cannot be renewed; open a new connection.
362
+
363
+ Catch this class directly, or `DatabaseError`, to stay correct once the
364
+ base changes to `OperationalError`.
365
+ """
366
+
367
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
368
+ super().__init__(*args, **kwargs)
369
+ # Snowpark reads ``ex.cause``; the old driver stored a ProgrammingError.
370
+ self.cause = ProgrammingError(*args, **kwargs)
371
+ _warn_future_base_change()
372
+
373
+
374
+ class MissingDependencyError(Error):
375
+ """Exception for missing extras dependencies."""
376
+
377
+ def __init__(self, dependency: str) -> None:
378
+ super().__init__(msg=f"Missing optional dependency: {dependency}")
379
+
380
+
381
+ class ConfigManagerError(Error):
382
+ """Exception raised for configuration manager errors."""
383
+
384
+ pass
385
+
386
+
387
+ class ConfigSourceError(Error):
388
+ """Exception raised when a configuration source has invalid values."""
389
+
390
+ pass
391
+
392
+
393
+ class MissingConfigOptionError(ConfigSourceError):
394
+ """Exception raised when a required configuration option is missing."""
395
+
396
+ pass
397
+
398
+
399
+ # ---------------------------------------------------------------------------
400
+ # Backward compatibility (importable, never raised by the universal core)
401
+ #
402
+ # See module docstring for rationale.
403
+ # ---------------------------------------------------------------------------
404
+
405
+
406
+ @backward_compatibility
407
+ class HttpError(Error):
408
+ """Old-driver general HTTP exception."""
409
+
410
+
411
+ @backward_compatibility
412
+ class BadRequest(Error):
413
+ """Old-driver exception for HTTP 400."""
414
+
415
+
416
+ @backward_compatibility
417
+ class ForbiddenError(Error):
418
+ """Old-driver exception for HTTP 403."""
419
+
420
+
421
+ @backward_compatibility
422
+ class MethodNotAllowed(Error):
423
+ """Old-driver exception for HTTP 405."""
424
+
425
+
426
+ @backward_compatibility
427
+ class RequestTimeoutError(Error):
428
+ """Old-driver exception for HTTP 408."""
429
+
430
+
431
+ @backward_compatibility
432
+ class TooManyRequests(Error):
433
+ """Old-driver exception for HTTP 429."""
434
+
435
+
436
+ @backward_compatibility
437
+ class InternalServerError(Error):
438
+ """Old-driver exception for HTTP 500."""
439
+
440
+
441
+ @backward_compatibility
442
+ class BadGatewayError(Error):
443
+ """Old-driver exception for HTTP 502."""
444
+
445
+
446
+ @backward_compatibility
447
+ class ServiceUnavailableError(Error):
448
+ """Old-driver exception for HTTP 503."""
449
+
450
+
451
+ @backward_compatibility
452
+ class GatewayTimeoutError(Error):
453
+ """Old-driver exception for HTTP 504."""
454
+
455
+
456
+ @backward_compatibility
457
+ class OtherHTTPRetryableError(Error):
458
+ """Old-driver exception for unclassified retryable HTTP errors."""
459
+
460
+
461
+ @backward_compatibility
462
+ class RefreshTokenError(Error):
463
+ """Old-driver internal signal for OAuth token refresh."""
464
+
465
+
466
+ @backward_compatibility
467
+ class TokenExpiredError(Error):
468
+ """Old-driver internal signal for expired session tokens."""
469
+
470
+
471
+ @backward_compatibility
472
+ class RevocationCheckError(OperationalError):
473
+ """Old-driver exception for OCSP/CRL revocation check failures."""
474
+
475
+
476
+ @backward_compatibility
477
+ class BindUploadError(Error):
478
+ """Old-driver exception for stage upload failures during array binding."""
479
+
480
+
481
+ @backward_compatibility
482
+ class RequestExceedMaxRetryError(Error):
483
+ """Old-driver exception for cloud storage REST calls exceeding max retries."""
484
+
485
+
486
+ @backward_compatibility
487
+ class PresignedUrlExpiredError(Error):
488
+ """Old-driver exception for expired cloud storage presigned URLs."""
489
+
490
+
491
+ # Must be the last statement; see ``install_backward_compatibility_getattr``.
492
+ install_backward_compatibility_getattr(__name__)
@@ -0,0 +1,71 @@
1
+ """BACKWARD COMPATIBILITY MODULE ONLY — legacy authenticator-type constants.
2
+
3
+ This module is itself deprecated and exists only for backward compatibility:
4
+ it re-exports legacy flat authenticator-type constants for drop-in parity
5
+ with snowflake-connector-python's ``network.py``. None of these are used by
6
+ the Universal Driver; they are retained so downstream consumers that import
7
+ them at module load (e.g. dbt-adapters' Workload Identity Federation support)
8
+ keep working. Each warns once on first external access, like the legacy
9
+ classes in ``errors.py`` / ``result_batch.py``. There is no non-deprecated
10
+ successor to migrate to: pass the raw authenticator string (e.g.
11
+ ``"OAUTH"``) to ``authenticator=`` directly, or use
12
+ ``snowflake.connector.constants.AuthenticatorType`` — also retained only
13
+ for compatibility with the enum-based style — if a typed value is more
14
+ convenient.
15
+
16
+ The values here are not written out again: each is taken from
17
+ :class:`~snowflake.connector._internal.authenticator_type.AuthenticatorType`,
18
+ which is the one place the list lives on the Python side and which carries the
19
+ note on keeping it in sync with the Rust core. Add or change a value there, not
20
+ here.
21
+
22
+ ``ReauthenticationRequest`` is the exception to that: Snowpark still imports
23
+ it from this module, so it is re-exported without a deprecation warning.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ from ._internal.backward_compatibility import install_backward_compatibility_getattr
29
+ from ._internal.decorators import backward_compatibility
30
+ from .constants import AuthenticatorType
31
+ from .errors import ReauthenticationRequest
32
+
33
+
34
+ # ``.value`` (a plain ``str``) rather than the enum member: matches the upstream
35
+ # snowflake-connector-python driver, which had these as plain string constants
36
+ # (e.g. ``DEFAULT_AUTHENTICATOR = "SNOWFLAKE"``), not enum members — so this is
37
+ # drop-in type parity, not just an implementation detail. It also sidesteps a
38
+ # subtlety in ``TestNoInternalImportsOfBackwardCompatNames``: that guard test
39
+ # flags a marked value whose ``__module__`` differs from the module it's found
40
+ # in, and an enum member inherits ``__module__`` from wherever
41
+ # ``AuthenticatorType`` is defined (``_internal.authenticator_type``, not
42
+ # ``network``). A plain ``str`` has no ``__module__`` at all, so it can't trip
43
+ # that check.
44
+ DEFAULT_AUTHENTICATOR = backward_compatibility(AuthenticatorType.DEFAULT.value)
45
+ EXTERNAL_BROWSER_AUTHENTICATOR = backward_compatibility(AuthenticatorType.EXTERNAL_BROWSER.value)
46
+ KEY_PAIR_AUTHENTICATOR = backward_compatibility(AuthenticatorType.KEY_PAIR.value)
47
+ OAUTH_AUTHENTICATOR = backward_compatibility(AuthenticatorType.OAUTH.value)
48
+ OAUTH_AUTHORIZATION_CODE = backward_compatibility(AuthenticatorType.OAUTH_AUTHORIZATION_CODE.value)
49
+ OAUTH_CLIENT_CREDENTIALS = backward_compatibility(AuthenticatorType.OAUTH_CLIENT_CREDENTIALS.value)
50
+ USR_PWD_MFA_AUTHENTICATOR = backward_compatibility(AuthenticatorType.USERNAME_PASSWORD_MFA.value)
51
+ PROGRAMMATIC_ACCESS_TOKEN = backward_compatibility(AuthenticatorType.PROGRAMMATIC_ACCESS_TOKEN.value)
52
+ PAT_WITH_EXTERNAL_SESSION = backward_compatibility(AuthenticatorType.PAT_WITH_EXTERNAL_SESSION.value)
53
+ WORKLOAD_IDENTITY_AUTHENTICATOR = backward_compatibility(AuthenticatorType.WORKLOAD_IDENTITY.value)
54
+
55
+ __all__ = [
56
+ "AuthenticatorType",
57
+ "DEFAULT_AUTHENTICATOR",
58
+ "EXTERNAL_BROWSER_AUTHENTICATOR",
59
+ "KEY_PAIR_AUTHENTICATOR",
60
+ "OAUTH_AUTHENTICATOR",
61
+ "OAUTH_AUTHORIZATION_CODE",
62
+ "OAUTH_CLIENT_CREDENTIALS",
63
+ "USR_PWD_MFA_AUTHENTICATOR",
64
+ "PROGRAMMATIC_ACCESS_TOKEN",
65
+ "PAT_WITH_EXTERNAL_SESSION",
66
+ "WORKLOAD_IDENTITY_AUTHENTICATOR",
67
+ "ReauthenticationRequest",
68
+ ]
69
+
70
+ # Must be the last statement; see ``install_backward_compatibility_getattr``.
71
+ install_backward_compatibility_getattr(__name__)