From c7f474300a4f259a9894cc446f7dc70eff8935f1 Mon Sep 17 00:00:00 2001 From: changyonglik Date: Thu, 8 Sep 2022 21:14:23 +0900 Subject: [PATCH 1/3] Added _scproxy necessary for MacOS Signed-off-by: changyonglik --- registry/sql-registry/registry/database.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/registry/sql-registry/registry/database.py b/registry/sql-registry/registry/database.py index 39bab8ec4..f2fb7aae6 100644 --- a/registry/sql-registry/registry/database.py +++ b/registry/sql-registry/registry/database.py @@ -3,6 +3,7 @@ import logging import threading import os +import _scproxy import pymssql @@ -53,7 +54,7 @@ def __init__(self, params): self.params = params self.make_connection() self.mutex = threading.Lock() - + def make_connection(self): self.conn = pymssql.connect(**self.params) @@ -85,10 +86,10 @@ def transaction(self): """ Start a transaction so we can run multiple SQL in one batch. User should use `with` with the returned value, look into db_registry.py for more real usage. - + NOTE: `self.query` and `self.execute` will use a different MSSQL connection so any change made in this transaction will *not* be visible in these calls. - + The minimal implementation could look like this if the underlying engine doesn't support transaction. ``` @contextmanager @@ -125,4 +126,4 @@ def connect(*args, **kargs): ret = p.connect(*args, **kargs) if ret is not None: return ret - raise RuntimeError("Cannot connect to database") \ No newline at end of file + raise RuntimeError("Cannot connect to database") From 75c18fccb837188bb2ffe2b525ef354484007005 Mon Sep 17 00:00:00 2001 From: changyonglik Date: Thu, 8 Sep 2022 22:14:16 +0900 Subject: [PATCH 2/3] Changed to conditional import Signed-off-by: changyonglik --- registry/sql-registry/registry/database.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/registry/sql-registry/registry/database.py b/registry/sql-registry/registry/database.py index f2fb7aae6..1e534968b 100644 --- a/registry/sql-registry/registry/database.py +++ b/registry/sql-registry/registry/database.py @@ -3,7 +3,9 @@ import logging import threading import os -import _scproxy +import platform +if platform.system().lower().startswith('dar'): + import _scproxy import pymssql From 625d9ebaa23700ef48f95a0c96c3d410099c2385 Mon Sep 17 00:00:00 2001 From: changyonglik Date: Thu, 8 Sep 2022 22:23:32 +0900 Subject: [PATCH 3/3] Added comments Signed-off-by: changyonglik --- registry/sql-registry/registry/database.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/registry/sql-registry/registry/database.py b/registry/sql-registry/registry/database.py index 1e534968b..21b8a2aca 100644 --- a/registry/sql-registry/registry/database.py +++ b/registry/sql-registry/registry/database.py @@ -3,9 +3,13 @@ import logging import threading import os + +# Checks if the platform is Max (Darwin). +# If so, imports _scproxy that is necessary for pymssql to work on MacOS import platform if platform.system().lower().startswith('dar'): import _scproxy + import pymssql