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

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

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

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
 
 
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] https://issues.apache.org/jira/browse/AIRFLOW-3618
   
   ### Description
   
   - [x] The airflow.models.connection.Connection class function get_hook did not work as expected. The `conn_type` was not guaranteed to be lower case, and the get_hook function expected all lowercase type names. By updating the code so that the conditionals used `self.conn_type.lower()` instead of just `self.conn_type`, we can now make sure that the conditionals match the expected. 
   
   For example:
   ```
   >>> 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'>
   ```
   
   ### Tests
   
   - [x] Does not need tests as it is updating existing functionality which should already have test associated.
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [x] No new documentation is needed as the change is a bug fix which does not change the expected functionality of the function `Connection.get_hook`.
   
   ### Code Quality
   
   - [x] Passes `flake8`
 
----------------------------------------------------------------
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:
users@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)