[ 
https://issues.apache.org/jira/browse/AIRFLOW-3265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16666513#comment-16666513
 ] 

ASF GitHub Bot commented on AIRFLOW-3265:
-----------------------------------------

Fokko closed pull request #4110: [AIRFLOW-3265] Support for "unix_socket" extra 
for MySQL hook
URL: https://github.com/apache/incubator-airflow/pull/4110
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/hooks/mysql_hook.py b/airflow/hooks/mysql_hook.py
index 9ec8ca4d3e..1ea3484f88 100644
--- a/airflow/hooks/mysql_hook.py
+++ b/airflow/hooks/mysql_hook.py
@@ -89,6 +89,8 @@ def get_conn(self):
         local_infile = conn.extra_dejson.get('local_infile', False)
         if conn.extra_dejson.get('ssl', False):
             conn_config['ssl'] = conn.extra_dejson['ssl']
+        if conn.extra_dejson.get('unix_socket'):
+            conn_config['unix_socket'] = conn.extra_dejson['unix_socket']
         if local_infile:
             conn_config["local_infile"] = 1
         conn = MySQLdb.connect(**conn_config)
diff --git a/tests/hooks/test_mysql_hook.py b/tests/hooks/test_mysql_hook.py
index 415d430fc4..e6c64f7c5c 100644
--- a/tests/hooks/test_mysql_hook.py
+++ b/tests/hooks/test_mysql_hook.py
@@ -92,6 +92,15 @@ def test_get_conn_local_infile(self, mock_connect):
         self.assertEqual(args, ())
         self.assertEqual(kwargs['local_infile'], 1)
 
+    @mock.patch('airflow.hooks.mysql_hook.MySQLdb.connect')
+    def test_get_con_unix_socket(self, mock_connect):
+        self.connection.extra = json.dumps({'unix_socket': "/tmp/socket"})
+        self.db_hook.get_conn()
+        mock_connect.assert_called_once()
+        args, kwargs = mock_connect.call_args
+        self.assertEqual(args, ())
+        self.assertEqual(kwargs['unix_socket'], '/tmp/socket')
+
 
 class TestMySqlHook(unittest.TestCase):
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Mysql Hook does not support "unix_socket" extra
> -----------------------------------------------
>
>                 Key: AIRFLOW-3265
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-3265
>             Project: Apache Airflow
>          Issue Type: Improvement
>          Components: database
>            Reporter: Jarek Potiuk
>            Assignee: Jarek Potiuk
>            Priority: Minor
>             Fix For: 2.0.0
>
>
> MySQL hook does not support "unix_socket" extra - which allows to specify 
> different location of linux socket than the default one. This is a blocker 
> for tools like cloud-sql-proxy that creates sockets in an arbitrary place.
> I will provide fix shortly.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to