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 2018/12/17 23:53:01 UTC

[jira] [Commented] (AIRFLOW-1595) SqliteHook is broken

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

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

stale[bot] closed pull request #2598: [AIRFLOW-1595] Change to construct sqlite_hook from connection schema
URL: https://github.com/apache/incubator-airflow/pull/2598
 
 
   

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/sqlite_hook.py b/airflow/hooks/sqlite_hook.py
index c241c2ddef..5a9c7e3516 100644
--- a/airflow/hooks/sqlite_hook.py
+++ b/airflow/hooks/sqlite_hook.py
@@ -32,5 +32,5 @@ def get_conn(self):
         Returns a sqlite connection object
         """
         conn = self.get_connection(self.sqlite_conn_id)
-        conn = sqlite3.connect(conn.host)
+        conn = sqlite3.connect(conn.schema)
         return conn
diff --git a/airflow/utils/db.py b/airflow/utils/db.py
index 35c187ca54..44aa05429d 100644
--- a/airflow/utils/db.py
+++ b/airflow/utils/db.py
@@ -160,7 +160,7 @@ def initdb():
     merge_conn(
         models.Connection(
             conn_id='sqlite_default', conn_type='sqlite',
-            host='/tmp/sqlite_default.db'))
+            schema='/tmp/sqlite_default.db'))
     merge_conn(
         models.Connection(
             conn_id='http_default', conn_type='http',
diff --git a/tests/hooks/test_sqlite_hook.py b/tests/hooks/test_sqlite_hook.py
new file mode 100644
index 0000000000..de830f09ae
--- /dev/null
+++ b/tests/hooks/test_sqlite_hook.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import mock
+import unittest
+import os
+
+from airflow import settings, models
+from airflow.settings import Session
+from airflow.hooks.sqlite_hook import SqliteHook
+
+
+@unittest.skipIf(not settings.SQL_ALCHEMY_CONN.startswith('sqlite'), 'SqliteHook won\'t work without backend SQLite. No need to test anything here')
+class TestSqliteHook(unittest.TestCase):
+
+    CONN_ID = 'sqlite_hook_test'
+
+    @classmethod
+    def setUpClass(cls):
+        super(TestSqliteHook, cls).setUpClass()
+        session = Session()
+        session.query(models.Connection).filter_by(conn_id=cls.CONN_ID).delete()
+        session.commit()
+        connection = models.Connection(conn_id=cls.CONN_ID, uri=settings.SQL_ALCHEMY_CONN)
+        session.add(connection)
+        session.commit()
+        session.close()
+
+    def test_sql_hook(self):
+        hook = SqliteHook(sqlite_conn_id=self.CONN_ID)
+        conn_id, = hook.get_first('SELECT conn_id FROM connection WHERE conn_id = :conn_id',
+                                  {'conn_id': self.CONN_ID})
+        self.assertEqual(conn_id, self.CONN_ID)
+
+    @classmethod
+    def tearDownClass(cls):
+        session = Session()
+        session.query(models.Connection).filter_by(conn_id=cls.CONN_ID).delete()
+        session.commit()
+        session.close()
+        super(TestSqliteHook, cls).tearDownClass()


 

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


> SqliteHook is broken
> --------------------
>
>                 Key: AIRFLOW-1595
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-1595
>             Project: Apache Airflow
>          Issue Type: Bug
>          Components: hooks
>    Affects Versions: 1.8.1
>            Reporter: Shintaro Murakami
>            Priority: Major
>
> SqliteHook is built using the host attribute of connection, but correctly we should use the schema attribute. The path to the DB parsed from the URI is set as schema.



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