You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2020/06/12 21:21:19 UTC

[airflow] branch imap-default-conn-type created (now a31ad49)

This is an automated email from the ASF dual-hosted git repository.

ash pushed a change to branch imap-default-conn-type
in repository https://gitbox.apache.org/repos/asf/airflow.git.


      at a31ad49  Update (previously null) imap_default conn_type

This branch includes the following new commits:

     new a31ad49  Update (previously null) imap_default conn_type

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[airflow] 01/01: Update (previously null) imap_default conn_type

Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch imap-default-conn-type
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit a31ad49e7bf7c8ba33878c0aea8cdc0532b5d933
Author: Ash Berlin-Taylor <as...@firemirror.com>
AuthorDate: Fri Jun 12 22:17:45 2020 +0100

    Update (previously null) imap_default conn_type
    
    This is a test fixup to #9187, and updates the possibly existing
    imap_default connection, and adds that hook type to the various lists
---
 .../8f966b9c467a_set_conn_type_as_non_nullable.py   | 21 +++++++++++++++++++++
 airflow/models/connection.py                        |  2 ++
 tests/providers/imap/hooks/test_imap.py             |  1 +
 3 files changed, 24 insertions(+)

diff --git a/airflow/migrations/versions/8f966b9c467a_set_conn_type_as_non_nullable.py b/airflow/migrations/versions/8f966b9c467a_set_conn_type_as_non_nullable.py
index 6cf16c4..8ebb8af 100644
--- a/airflow/migrations/versions/8f966b9c467a_set_conn_type_as_non_nullable.py
+++ b/airflow/migrations/versions/8f966b9c467a_set_conn_type_as_non_nullable.py
@@ -26,6 +26,7 @@ Create Date: 2020-06-08 22:36:34.534121
 
 import sqlalchemy as sa
 from alembic import op
+from sqlalchemy.ext.declarative import declarative_base
 
 # revision identifiers, used by Alembic.
 revision = "8f966b9c467a"
@@ -37,6 +38,26 @@ depends_on = None
 def upgrade():
     """Apply Set conn_type as non-nullable"""
 
+    Base = declarative_base()
+
+    class Connection(Base):
+        __tablename__ = "connection"
+
+        id = sa.Column(sa.Integer(), primary_key=True)
+        conn_id = sa.Column(sa.String(250))
+        conn_type = sa.Column(sa.String(500))
+
+    # Generate run type for existing records
+    connection = op.get_bind()
+    sessionmaker = sa.orm.sessionmaker()
+    session = sessionmaker(bind=connection)
+
+    # imap_default was missing it's type, let's fix that up
+    session.query(Connection).filter_by(conn_id="imap_default", conn_type=None).update(
+        {Connection.conn_type: "imap"}, synchronize_session=False
+    )
+    session.commit()
+
     with op.batch_alter_table("connection", schema=None) as batch_op:
         batch_op.alter_column("conn_type", existing_type=sa.VARCHAR(length=500), nullable=False)
 
diff --git a/airflow/models/connection.py b/airflow/models/connection.py
index 7e525dd..8234efb 100644
--- a/airflow/models/connection.py
+++ b/airflow/models/connection.py
@@ -64,6 +64,7 @@ CONN_TYPE_TO_HOOK = {
     "grpc": ("airflow.providers.grpc.hooks.grpc.GrpcHook", "grpc_conn_id"),
     "hive_cli": ("airflow.providers.apache.hive.hooks.hive.HiveCliHook", "hive_cli_conn_id"),
     "hiveserver2": ("airflow.providers.apache.hive.hooks.hive.HiveServer2Hook", "hiveserver2_conn_id"),
+    "imap": ("airflow.providers.imap.hooks.imap.ImapHook", "imap_conn_id"),
     "jdbc": ("airflow.providers.jdbc.hooks.jdbc.JdbcHook", "jdbc_conn_id"),
     "jira": ("airflow.providers.jira.hooks.jira.JiraHook", "jira_conn_id"),
     "kubernetes": ("airflow.providers.cncf.kubernetes.hooks.kubernetes.KubernetesHook", "kubernetes_conn_id"),
@@ -172,6 +173,7 @@ class Connection(Base, LoggingMixin):
         ('tableau', 'Tableau'),
         ('kubernetes', 'Kubernetes cluster Connection'),
         ('spark', 'Spark'),
+        ('imap', 'IMAP')
     ]
 
     def __init__(
diff --git a/tests/providers/imap/hooks/test_imap.py b/tests/providers/imap/hooks/test_imap.py
index 7af38e9..ef3b998 100644
--- a/tests/providers/imap/hooks/test_imap.py
+++ b/tests/providers/imap/hooks/test_imap.py
@@ -55,6 +55,7 @@ class TestImapHook(unittest.TestCase):
         db.merge_conn(
             Connection(
                 conn_id='imap_default',
+                conn_type='imap',
                 host='imap_server_address',
                 login='imap_user',
                 password='imap_password'