-
Notifications
You must be signed in to change notification settings - Fork 149
Reject timestampAsString override on kernel sessions #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
84c36e6
2bfadd4
d367cf2
845fe55
acbe571
78bb069
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |
| SessionId, | ||
| ) | ||
| from databricks.sql.exc import ( | ||
| Error, | ||
| InterfaceError, | ||
| NotSupportedError, | ||
| ProgrammingError, | ||
|
|
@@ -63,6 +64,8 @@ | |
| # per-request skip-and-warn. | ||
| _KERNEL_MANAGED_HEADERS = frozenset({"authorization", "x-databricks-org-id"}) | ||
|
|
||
| TIMESTAMP_AS_STRING_CONFIG = "spark.thriftserver.arrowBasedRowSet.timestampAsString" | ||
|
|
||
| # Leading verbs of SQL volume/staging statements. Detected by the | ||
| # leading token (case-insensitive) so the kernel backend can fail loud | ||
| # on staging ops it can't service — see ``execute_command``. | ||
|
|
@@ -99,6 +102,21 @@ def _strip_leading_sql_comments(sql: str) -> str: | |
| return sql[i:] | ||
|
|
||
|
|
||
| def _check_session_configuration(session_configuration: Dict[str, str]) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Your point is valid and I can't confirm it from here:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Thrift one come in through ExecuteStatement and it is added by the python connector itself, but here you are guarding against OpenSession.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. The reviewer's point had converged (the
All 127 tests in Pushed acbe571.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch, thanks
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thread has converged: the requested change was already applied and pushed in commit acbe571 (removed |
||
| # This client expects timestampAsString to be false, so do not allow overrides. | ||
| if ( | ||
| session_configuration.get(TIMESTAMP_AS_STRING_CONFIG, "false").lower() | ||
| != "false" | ||
| ): | ||
| raise Error( | ||
| "Invalid session configuration: {} cannot be changed " | ||
| "while using the Databricks SQL connector, it must be false not {}".format( | ||
| TIMESTAMP_AS_STRING_CONFIG, | ||
| session_configuration[TIMESTAMP_AS_STRING_CONFIG], | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| def _is_not_found(exc: BaseException) -> bool: | ||
| """True iff ``exc`` is a kernel ``NotFound`` error (HTTP 404 / | ||
| ``STATEMENT_NOT_FOUND``). | ||
|
|
@@ -310,16 +328,29 @@ def open_session( | |
| session_conf: Optional[Dict[str, str]] = None | ||
| if session_configuration: | ||
| session_conf = {k: str(v) for k, v in session_configuration.items()} | ||
| # The kwarg builds run INSIDE the try so the ``finally`` scrub | ||
| # below always fires — including when ``kernel_auth_kwargs`` | ||
| # The kwarg builds — and the session-conf validation — run INSIDE | ||
| # the try so the ``finally`` scrub below always fires, including | ||
| # when the validation rejects or when ``kernel_auth_kwargs`` | ||
| # itself raises mid-build (e.g. an OAuth token-exchange failure | ||
| # while the M2M secret is in hand). Pre-declared empty so the | ||
| # ``finally`` can reference them unconditionally even on an early | ||
| # raise. Building here (not in ``__init__``) keeps the bearer | ||
| # token's in-process lifetime as short as possible. | ||
| # while the M2M secret is in hand). ``self._auth_options`` already | ||
| # holds the secret at this point (set in ``__init__``), so an | ||
| # early raise before the try would leave it un-scrubbed. Pre-declared | ||
| # empty so the ``finally`` can reference them unconditionally even | ||
| # on an early raise. Building here (not in ``__init__``) keeps the | ||
| # bearer token's in-process lifetime as short as possible. | ||
| auth_kwargs: Dict[str, Any] = {} | ||
| tls_kwargs: Dict[str, Any] = {} | ||
| try: | ||
| if session_conf is not None: | ||
| # ``_check_session_configuration`` only *rejects* a non-``false`` | ||
| # ``TIMESTAMP_AS_STRING_CONFIG`` override; unlike the Thrift backend | ||
| # (``thrift_backend.py``), it deliberately does NOT inject | ||
| # ``TIMESTAMP_AS_STRING_CONFIG = "false"`` into ``session_conf``. | ||
| # The kernel owns type handling natively (Arrow / complex-types), | ||
| # and the Thrift-specific conf may be unsupported on the SEA session | ||
| # path, so pinning it here would be redundant at best and rejected | ||
| # at worst. The divergence is intentional, not accidental. | ||
| _check_session_configuration(session_conf) | ||
| auth_kwargs = kernel_auth_kwargs( | ||
| self._auth_provider, | ||
| self._auth_options, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.