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

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

griff122 commented on pull request #4423: [AIRFLOW-3618] - Fix 
models.connection.Connection get_hook function
URL: https://github.com/apache/incubator-airflow/pull/4423
 
 
   
 
----------------------------------------------------------------
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:
us...@infra.apache.org


> airflow.models.connection.Connection class function get_hook doesn't work
> -------------------------------------------------------------------------
>
>                 Key: AIRFLOW-3618
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-3618
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: models
>    Affects Versions: 1.10.1
>         Environment: MacOS, iTerm, python 3.5.2
>            Reporter: Ryan Griffin
>            Priority: Major
>   Original Estimate: 0.5h
>  Remaining Estimate: 0.5h
>
> The airflow.models.connection.Connection class function get_hook does not 
> work as expected. 
> It is currently using self.conn_type == 'type', where the 'type' is always 
> lowercase. In practice this is not true, and causes the get_hook function to 
> always return a NoneType. 
> Here is an example:
> {code:java}
> >>> import airflow
> >>> from airflow.hooks.base_hook import BaseHook
> >>> airflow.__version__
> '1.10.1'
> >>> conn = BaseHook.get_connection('test_local_mysql')
> [2019-01-02 11:36:15,530] {base_hook.py:83} INFO - Using connection to: 
> localhost
> >>> conn.conn_type
> 'MySQL'
> >>> type(conn.get_hook())
> <class 'NoneType'>
> >>> conn.conn_type = conn.conn_type.lower()
> >>> conn.conn_type
> 'mysql'
> >>> type(conn.get_hook())
> <class 'airflow.hooks.mysql_hook.MySqlHook'>{code}
>  
> As you can see, when using the BaseHook class to get the connection, the 
> conn_type is *MySQL* instead of *mysql*, so it is unable to find the correct 
> type to get the hook (reference: 
> [https://github.com/apache/incubator-airflow/blob/master/airflow/models/connection.py#L178).]
> By forcing the conn_type to be lowercase, the *get_hook* function now works. 



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

Reply via email to