You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/09/01 09:23:06 UTC

[GitHub] [airflow] potiuk commented on a change in pull request #17935: Fix instantiating Vault Secret Backend during configuration

potiuk commented on a change in pull request #17935:
URL: https://github.com/apache/airflow/pull/17935#discussion_r699203356



##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -206,7 +205,7 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
 
         return response.get("conn_uri") if response else None
 
-    def get_connection(self, conn_id: str) -> Optional[Connection]:
+    def get_connection(self, conn_id: str) -> Any:  # Do not change it to Connection (see below!)

Review comment:
       Updated. Good point!

##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -206,7 +205,12 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
 
         return response.get("conn_uri") if response else None
 
-    def get_connection(self, conn_id: str) -> Optional[Connection]:
+    # Make sure connection is imported this way for type checking, otherwise when importing
+    # the backend it will get a circular dependency and fail
+    if TYPE_CHECKING:
+        from airflow.models.connection import Connection

Review comment:
       I actually deliberately wanted to keep it in one place, to avoid any accidental removal. It's pretty "special" case (which eventually we might be able to remove) :)

##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -206,7 +205,12 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
 
         return response.get("conn_uri") if response else None
 
-    def get_connection(self, conn_id: str) -> Optional[Connection]:
+    # Make sure connection is imported this way for type checking, otherwise when importing
+    # the backend it will get a circular dependency and fail
+    if TYPE_CHECKING:
+        from airflow.models.connection import Connection

Review comment:
       BTW. I did not even know that you can do such statements at the class level . But it worked.

##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -206,7 +205,12 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
 
         return response.get("conn_uri") if response else None
 
-    def get_connection(self, conn_id: str) -> Optional[Connection]:
+    # Make sure connection is imported this way for type checking, otherwise when importing
+    # the backend it will get a circular dependency and fail
+    if TYPE_CHECKING:
+        from airflow.models.connection import Connection

Review comment:
       TIL: https://docs.python.org/3/tutorial/classes.html#class-definition-syntax
   
   > In practice, the statements inside a class definition will usually be function definitions, but other statements are allowed, and sometimes useful — we’ll come back to this later. The function definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods — again, this is explained later.
   
   

##########
File path: airflow/providers/hashicorp/secrets/vault.py
##########
@@ -206,7 +205,12 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
 
         return response.get("conn_uri") if response else None
 
-    def get_connection(self, conn_id: str) -> Optional[Connection]:
+    # Make sure connection is imported this way for type checking, otherwise when importing
+    # the backend it will get a circular dependency and fail
+    if TYPE_CHECKING:
+        from airflow.models.connection import Connection

Review comment:
       TIL: https://docs.python.org/3/tutorial/classes.html#class-definition-syntax
   
   > In practice, the statements inside a class definition will usually be function definitions, but other statements are allowed, and sometimes useful — we’ll come back to this later. The function definitions inside a class normally have a peculiar form of argument list, dictated by the calling conventions for methods — again, this is explained later.
   
   Perfecly legitimate use case IMHO  :D ..




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