Skip to content

Commit 5078e57

Browse files
NiallEgansusodapop
authored andcommitted
Make regex more robust for PySQL recognition
Our regex was a little bit off; it would have not fully been able to parse version numbers with `rc`, `a` appendages etc. As it happens, our version number was not in canonical form in anycase. We were also missing the parsing for PySQL client in the log redactor (which is used for a new pipeline that is being developed by the data team). This PR fixes those things. * Unit test in py client(s) to make sure version number is canonical
1 parent 057ea0e commit 5078e57

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

cmdexec/clients/python/src/databricks/sql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __repr__(self):
2020
DATE = _DBAPITypeObject('date')
2121
ROWID = _DBAPITypeObject()
2222

23-
__version__ = "2.0.0-rc1"
23+
__version__ = "2.0.0rc1"
2424
USER_AGENT_NAME = "PyDatabricksSqlConnector"
2525

2626

cmdexec/clients/python/src/databricks/sql/thrift_backend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ def make_request(self, method, request, attempt_number=1):
110110
# We do not want threads to be simultaneously sharing the Thrift Transport
111111
# because we use its state to determine retries
112112
self._request_lock.acquire()
113+
logger.warning("Sending request: {}".format(request))
113114
response = method(request)
114-
logger.debug("Received response: {}".format(response))
115+
logger.warning("Received response: {}".format(response))
115116
ThriftBackend._check_response_for_error(response)
116117
return response
117118
except Exception as error:

cmdexec/clients/python/tests/tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import sys
23
import unittest
34
from unittest.mock import patch, MagicMock, Mock
@@ -331,6 +332,12 @@ def test_max_number_of_retries_passthrough(self, mock_client_class):
331332

332333
self.assertEqual(mock_client_class.call_args[1]["_retry_stop_after_attempts_count"], 54)
333334

335+
def test_version_is_canonical(self):
336+
version = databricks.sql.__version__
337+
canonical_version_re = r'^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*((a|b|rc)' \
338+
r'(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev(0|[1-9][0-9]*))?$'
339+
self.assertIsNotNone(re.match(canonical_version_re, version))
340+
334341

335342
if __name__ == '__main__':
336343
suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])

0 commit comments

Comments
 (0)