You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Ryan Griffin (JIRA)" <ji...@apache.org> on 2019/01/02 16:44:00 UTC

[jira] [Created] (AIRFLOW-3618) airflow.models.connection.Connection class function get_hook doesn't work

Ryan Griffin created AIRFLOW-3618:
-------------------------------------

             Summary: 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


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)