zhongjiajie commented on a change in pull request #7903: Add conn_name and 
get_connection to dbapi_hook
URL: https://github.com/apache/airflow/pull/7903#discussion_r404662162
 
 

 ##########
 File path: airflow/hooks/dbapi_hook.py
 ##########
 @@ -62,15 +63,31 @@ def __init__(self, *args, **kwargs):
             raise AirflowException("conn_name_attr is not defined")
         elif len(args) == 1:
             setattr(self, self.conn_name_attr, args[0])
-        elif self.conn_name_attr not in kwargs:
-            setattr(self, self.conn_name_attr, self.default_conn_name)
         else:
-            setattr(self, self.conn_name_attr, kwargs[self.conn_name_attr])
+            setattr(self, self.conn_name_attr, kwargs.get(self.conn_name_attr, 
self.default_conn_name))
+
+    @property
+    def conn_name(self) -> str:
+        """
+        Get the name of the database connection attribute which identifies the 
connection.
+        """
+        return getattr(self, self.conn_name_attr)
+
+    def get_connection(self, conn_id: Optional[str] = None) -> Connection:
 
 Review comment:
   Emmy, I think we get some problem here, `mypy` unhappy and said `76: error: 
Signature of "get_connection" incompatible with supertype "BaseHook"`, because 
in `BaseHook` function `get_connection` is `classmethod`, but in `DbApiHook` 
function `get_connection` we use `getattr(self, self.conn_name_attr)` so have 
to be instance method.
   
   And `DbApiHook` we do not need to pass `conn_id` anymore, and I think we 
should change function `get_connection` to `@property connection` here. WDYT

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


With regards,
Apache Git Services

Reply via email to