ashb commented on a change in pull request #10192:
URL: https://github.com/apache/airflow/pull/10192#discussion_r532555442



##########
File path: airflow/hooks/base_hook.py
##########
@@ -42,7 +43,12 @@ def get_connections(cls, conn_id: str) -> List[Connection]:
         :param conn_id: connection id
         :return: array of connections
         """
-        return Connection.get_connections_from_secrets(conn_id)
+        warnings.warn(
+            "`BaseHook.get_connections` method will be deprecated in the 
future."
+            "Please use `BaseHook.get_connection` instead.",
+            PendingDeprecationWarning,

Review comment:
       ```suggestion
               PendingDeprecationWarning,
               stacklevel=2,
   ```

##########
File path: airflow/secrets/metastore.py
##########
@@ -31,12 +31,25 @@ class MetastoreBackend(BaseSecretsBackend):
 
     # pylint: disable=missing-docstring
     @provide_session
-    def get_connections(self, conn_id, session=None) -> List['Connection']:
+    def get_connection(self, conn_id, session=None) -> Optional['Connection']:
         from airflow.models.connection import Connection
 
-        conn_list = session.query(Connection).filter(Connection.conn_id == 
conn_id).all()
+        conn = session.query(Connection).filter(Connection.conn_id == 
conn_id).first()
         session.expunge_all()
-        return conn_list
+        return conn
+
+    # pylint: disable=missing-docstring
+    @provide_session
+    def get_connections(self, conn_id, session=None) -> List['Connection']:
+        warnings.warn(
+            "This method is deprecated. Please use "
+            "`airflow.secrets.metastore.MetastoreBackend.get_connection`.",
+            PendingDeprecationWarning,

Review comment:
       ```suggestion
               PendingDeprecationWarning,
               stacklevel=3,
   ```
   
   (+1 here because of the decorator.)

##########
File path: airflow/secrets/local_filesystem.py
##########
@@ -310,16 +313,27 @@ def _local_variables(self) -> Dict[str, str]:
         return secrets
 
     @property
-    def _local_connections(self) -> Dict[str, List[Any]]:
+    def _local_connections(self) -> Dict[str, 'Connection']:
         if not self.connections_file:
             self.log.debug("The file for connection is not specified. 
Skipping")
             # The user may not specify any file.
             return {}
         return load_connections_dict(self.connections_file)
 
-    def get_connections(self, conn_id: str) -> List[Any]:
+    def get_connection(self, conn_id: str) -> Optional['Connection']:
         if conn_id in self._local_connections:
-            return [self._local_connections[conn_id]]
+            return self._local_connections[conn_id]
+        return None
+
+    def get_connections(self, conn_id: str) -> List[Any]:
+        warnings.warn(
+            "This method is deprecated. Please use "
+            
"`airflow.secrets.local_filesystem.LocalFilesystemBackend.get_connection`.",
+            PendingDeprecationWarning,

Review comment:
       ```suggestion
               PendingDeprecationWarning,
               stacklevel=2,
   ```

##########
File path: airflow/secrets/base_secrets.py
##########
@@ -62,9 +63,26 @@ def get_connections(self, conn_id: str) -> 
List['Connection']:
 
         conn_uri = self.get_conn_uri(conn_id=conn_id)
         if not conn_uri:
-            return []
+            return None
         conn = Connection(conn_id=conn_id, uri=conn_uri)
-        return [conn]
+        return conn
+
+    def get_connections(self, conn_id: str) -> List['Connection']:
+        """
+        Return connection object with a given ``conn_id``.
+
+        :param conn_id: connection id
+        :type conn_id: str
+        """
+        warnings.warn(
+            "This method is deprecated. Please use "
+            
"`airflow.secrets.base_secrets.BaseSecretsBackend.get_connection`.",
+            PendingDeprecationWarning,

Review comment:
       ```suggestion
               PendingDeprecationWarning,
               stacklevel=2,
   ```




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to