You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "feluelle (via GitHub)" <gi...@apache.org> on 2023/02/14 07:16:30 UTC

[GitHub] [airflow] feluelle commented on a diff in pull request #28721: Use connection URI in SqliteHook

feluelle commented on code in PR #28721:
URL: https://github.com/apache/airflow/pull/28721#discussion_r1105389857


##########
airflow/providers/sqlite/hooks/sqlite.py:
##########
@@ -33,13 +34,20 @@ class SqliteHook(DbApiHook):
 
     def get_conn(self) -> sqlite3.dbapi2.Connection:
         """Returns a sqlite connection object"""
-        conn_id = getattr(self, self.conn_name_attr)
-        airflow_conn = self.get_connection(conn_id)
-        conn = sqlite3.connect(airflow_conn.host)
+        # The sqlite3 connection does not use the sqlite prefix.
+        # See https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#connect-strings for details.
+        uri = self.get_uri().replace("sqlite:///", "file:")
+        conn = sqlite3.connect(uri, uri=True)

Review Comment:
   Yes, it does. For example, see the last example [here](https://docs.python.org/3/library/sqlite3.html#how-to-work-with-sqlite-uris).
   > db = "file:mem1?mode=memory&cache=shared"
   > con1 = sqlite3.connect(db, uri=True)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org